Skip to content Skip to sidebar Skip to footer

Textview Display In Android From Sqlite

In my application I have one listview, in that I am displaying data from database. Following is my code: for(int i=1;i<=db.getAllTitles().getCount();i++) {

Solution 1:

In listview only possible to load one items only. Not supported to load more than one. Please try to display via grid view with the same syntax. If you want to try in list view then you should add the columns via Base adapter to list view. Please see the given tutorial link for base adapter.It will help you, http://developerlife.com/tutorials/?p=327

http://pradeep-sharma.com/blog/android-custom-listview-baseadapter-tutorial/

Solution 2:

Draw the Layout by this given coding,

showlist.xml:

<?xml version="1.0" encoding="utf-8"?><TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content" ><TableRowandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/Show"><TextViewandroid:layout_width="50dp"android:layout_height="20dp"android:textColor="#ff8000"android:id="@+id/Entry"android:layout_weight="1"android:gravity="left"/><TextViewandroid:layout_width="50dp"android:layout_height="20dp"android:textColor="#ff8000"android:id="@+id/sales"android:layout_weight="1"android:gravity="right" /></TableRow>

You can add the any no of textview here,I think you want to add four textview so you has to change the textview width as 25dp.

GridView set:

Then set simplecursoradapter for gridview coding as given

       ada=new SimpleCursorAdapter(context, R.layout.showlist, mon,newString[] { cname, "_id" }, newint[] { R.id.Entry,R.id.sales }) 

   gridview.setadapter(ada);

   //It will work well.

The main thing is you should create the gridview with mention the column is one.

The Result will be

enter image description here

Post a Comment for "Textview Display In Android From Sqlite"