How to divide and load a ListView in multiple parts?

Well implementing a button is easy enough: in your onCreate, load your adapter with the 1st 50 items, then implement a button with an onClickListener that adds the next 50 etc. HOWEVER I think what you really want to do is lazy load your listview so as they scroll, it will load more items - that why you don't need to clutter the UI with an extra button. For this your listactivity should implement OnScrollListener here is an example of that: Android Endless List.

From your question, it seems that you want to load few items initially and then load more items in future whenever user click on the "Load More items" button. For that there can be two cases possible: First case: webservice can send response in parts, like first time it sends 20 items, and next time 20 items whenever user clicks on "Load more items" button. Second case: If you get 500 items in response, then to implement "Load more items" kind of functionality, you have to create database table to store all the items.

Once you are done with database value storing, fetch 20 items initially, next time load 20 items and so on.

Initially load part of data in your list view. You have to use concept of Handler. Onclick event you have to send message to handler inside handler you have to write the logic to load your full data and call notifydataSetChanged method have a look on the sample code below.

Initially user is able to see some part of list. If user cvlicks on any list item then list user is able to see the whole list view. It is similar to as that you are expecting.

Sample Code import java.util. ArrayList; import android.app. ListActivity; import android.content.res.

Configuration; import android.os. Bundle; import android.os. Handler; import android.os.

Message; import android.view. View; import android.widget. AdapterView; import android.widget.AdapterView.

OnItemClickListener; import android.widget. ArrayAdapter; import android.widget. ListView; import android.widget.

Toast; public class MyListView extends ListActivity { ArrayList pens = new ArrayList(); ArrayAdapter arrayAdapter = null; private static final byte UPDATE_LIST = 100; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); pens.

Add("MONT Blanc"); pens. Add("Gucci"); pens. Add("Parker"); arrayAdapter = new ArrayAdapter(this, android.R.layout.

Simple_list_item_1, pens); setListAdapter(arrayAdapter); getListView(). SetTextFilterEnabled(true); ListView lv = getListView(); lv. SetOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub System.out.

Println("..Item is clicked.."); Message msg = new Message(); msg. What = UPDATE_LIST; updateListHandler. SendMessage(msg); } }); // System.out.

Println("....g1..."+PhoneNumberUtils. IsGlobalPhoneNumber("+912012185234")); // System.out. Println("....g2..."+PhoneNumberUtils.

IsGlobalPhoneNumber("120121852f4")); } @Override public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super. OnConfigurationChanged(newConfig); System.out. Println("...11configuration is changed..."); } void addMoreDataToList() { pens.

Add("item1"); pens. Add("item2"); pens. Add("item3"); } protected void onListItemClick(ListView l, View v, int position, long id) { super.

OnListItemClick(l, v, position, id); Object o = this.getListAdapter(). GetItem(position); String pen = o.toString(); Toast. MakeText(this, id + "You have chosen the pen: " + " " + pen, Toast.

LENGTH_LONG).show(); } private Handler updateListHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg. What) { case UPDATE_LIST: addMoreDataToList(); arrayAdapter. NotifyDataSetChanged(); break; } ; }; }; } Thanks Deepak.

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