android - Why does this code add a list item only once? -


i'm making button add list item each time click it. have code adds list item first time. how can make adds 1 each time click button. or maybe specific range of times?

declaration of variables in class.

//list of array strings serve list items arraylist<string> listitems = new arraylist<>();  //defining string adapter handle data of listview arrayadapter<string> adapterforpic;  //recording how many times button has been clicked int clickcounter=0; private listview mlistview; 

initialisation inside oncreate().

if (mlistview == null) {         mlistview = (listview) findviewbyid(r.id.photoslistview);     }      adapterforpic=new arrayadapter<>(this,             android.r.layout.simple_list_item_1,             listitems);     setlistadapter(adapterforpic); 

the methods inserting.

//method handle dynamic insertion public void additems(view v) {     listitems.add("clicked : "+clickcounter);     adapterforpic.notifydatasetchanged();     clickcounter++; }  protected listview getlistview() {     if (mlistview == null) {         mlistview = (listview) findviewbyid(r.id.photoslistview);     }     return mlistview; }  protected void setlistadapter(listadapter adapter) {     getlistview().setadapter(adapter); }  protected listadapter getlistadapter() {     listadapter adapter = getlistview().getadapter();     if (adapter instanceof headerviewlistadapter) {         return ((headerviewlistadapter)adapter).getwrappedadapter();     } else {         return adapter;     } } 

my problem in height of listview element. wrap_content , therefore showed me 1 list item.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -