i need to do pagination for listview.i.e i have static 10 text items.i need to show first 5 items in first page.when user clicks 'next' button remaining 5 text items should be displayed that replaces the old 5.How could i do this?
Corrected code....
public class listact extends ListActivity {
String str1,str2;
Button next;
TextView selection;
String[] items={"lorem", "ipsum", "dolor", "sit", "amet"};
String[] items1={"consectetuer","pepsi","coke","mirinda","tion"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
next=(Button)findViewById(R.id.next);
final ListView list = getListView();
ArrayAdapter<String> adapter = new ArrayAdapter<String开发者_如何学Go>(this,android.R.layout.simple_list_item_1,items);
list.setAdapter(adapter);
next.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(listact.this,android.R.layout.simple_list_item_1,items1);
list.setAdapter(adapter);
}
});
}
}
try this one.
ListView list = getListView();
CustomListAdapter adapter=new CustomListAdapter(listact.this,items);
list.setAdapter(adapter);
next.setOnClickListener(new OnClickListener()
{
public void onClick(View v) {
adapter.notifydatasetchanged();
CustomListAdapter adapter=new CustomListAdapter(listact.this,items1);
list.setAdapter(adapter);
}
});
May be i dono exactly...but create an array of first 5 items instead of 10. First time show 5 items in list view..
When next is clicked.. remove first items in array and add next 5 items in array.
then invalidate the adapter...by calling
adapter.notifydatasetchanged();
That will work..
just try this one...
ArrayAdapter<String> adapter; = new ArrayAdapter<String>(this,R.layout.row,R.id.txtlist,items);
lv.setAdapter(adapter);
next.setOnClickListener(new OnClickListener()
{
public void onClick(View v) {
adapter.notifydatasetchanged();
ArrayAdapter<String> adapter; = new ArrayAdapter<String>(this,R.layout.row,R.id.txtlist,items1);
lv.setAdapter(adapter);
}
});
in row.xml contain only textview
精彩评论