Show data from database by using ListView on Android?

Formula you might wanna consider using it's the Loader API, it's great because it help you handle your cursor and query efficiently.

Formula you might wanna consider using it's the Loader API, it's great because it help you handle your cursor and query efficiently. Loaders make it easy to asynchronously load data in an activity or fragment. They are available to every Activity and Fragment.

They provide asynchronous loading of data. They monitor the source of their data and deliver new results when the content changes. They automatically reconnect to the last loader's cursor when being recreated after a configuration change.

Thus, they don't need to re-query their data. Implements LoaderCallbacks in your ListView or ListFragment, then override the methods onCreateLoader, onFinishedLoader, onRestartLoader. Initialize your loader with the LoaderManager, getLoaderManager().

InitLoader, and enjoy. The only disadvantage that I've seen it's that is usefull if you have a ContentProvider, but even if you don't you can try some solutions in SO, like Loader without ContentProvider, In general i've learned that ContentProvider makes your life so much easier with the cursors, granted!.

You want to use a ListActivity. And you will need to create a cursor and query the data in the fillData method. Here's a decent tutorial on how to do that: vogella.de/articles/AndroidSQLite/articl....

Use ListView and SimpleCursor adapter. Example code can be found at: thinkandroid.wordpress.com/2010/01/09/si... vogella.de/articles/AndroidListView/arti....

Try this link for simple and easy understanding. This example will just answer your question. android-er.blogspot.com/2011/06/simple-e....

You can use a custom_adpater using SimpleCursorAdapter,for getting your database info. Displayed onto the listview. CustomAdpater.

Class: public class ShowNotificationAdapter extends SimpleCursorAdapter{ Cursor dataCursor; LayoutInflater mInflater; Context context; int layoutType; DatabaseHelper db_helper; public CustomAdapter(Context context, int layout, Cursor dataCursor, String from, int to) { super(context, layout, dataCursor, from, to); this. Context=context; this. DataCursor = dataCursor; mInflater = LayoutInflater.

From(context); db_helper=new DatabaseHelper(context); db_helper.open(); } @Override public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder holder; if(convertView==null) { convertView = mInflater. Inflate(R.layout. Custom_listitem, null); holder = new ViewHolder(); holder.Name=(TextView)convertView.

FindViewById(R.id. Name); holder. Quantity=(TextView)convertView.

FindViewById(R.id. Quantity); holder. OtherInfo=(TextView)convertView.

FindViewById(R.id. OtherInfo); } else { holder=(ViewHolder)convertView.getTag(); } dataCursor. MoveToPosition(position); String nameString=Integer.

ToString(dataCursor. GetString(dataCursor. GetColumnIndexOrThrow("name")));//column name of "name" holder.name.

SetText(nameString); String quantityString=dataCursor. GetString(dataCursor. GetColumnIndexOrThrow("quantity")); //column name of "quantity" holder.quantity.

SetText(quantityString); String otherInfoString=dataCursor. GetString(dataCursor. GetColumnIndexOrThrow("field_name")); holder.otherInfo.

SetText(quantityString); return convertView; } static class ViewHolder { TextView name; TextView quantity; TextView otherInfo; } @Override public Object getItem(int position) { return position; } } custom_listitem. Xml: MainActivity. Class: ... ListView listview=(ListView)findViewById(R.id.

Listview); Cursor cursor=; String from={"name","quantity"};//field names of 'name' and 'quantity' int to={R.id. Name,R.id. Quantity}; CustomAdapter ca=new CustomAdapter(context,R.layout.

Custom_listitem,cursor,from,to); listview. SetAdapter(ca); ca.notifyDataSetChanged(); ...

Thanks you for your coding. I am wondering about listitem.xml. Where is R.id.

Listview? I cannot find it. Is it possible to select the row for passing the edit page?

I want to make a list and each row can be clicked for edit. – wholee1 Nov 16 at 11:35 How can I write on Cursor cursor=;? – wholee1 Nov 16 at 11:52 You cannot edit listitem once it is listed.

Secondly,you need to work on basics of android first. Here,R.id. Listview simply the listview you defined in your layout file with id as "listview".

And also work on Cursor basics. It is really easiest code someone can give you! – ral Nov 16 at 11:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions