2013年9月16日星期一

[Android] How to replace the contents of

listview In a statement to instantiate a listview, and have the data myshow [] into the listview being . Now like listview inside a content point after , the replacement of lost content listview display the contents of another array . Feeling this part of the operation is very common , but so hard to find this part of the operation of the code or explain . Do we not use this method to display content do you ?
eliminating thank everyone for me , flattered .




        public class MainActivity extends Activity {
private CharSequence myshow[] = {"快乐大本营","O记快餐","大碗饭"};
private Spinner mealchoose = null;
private ListView showList = null;
private CharSequence promt = null;
ArrayAdapter<CharSequence> shopAdapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showList = (ListView) super.findViewById(R.id.shoplist);
shopAdapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_expandable_list_item_1,this.myshow);
showList.setAdapter(shopAdapter);
showList.setOnItemClickListener(new ShopReaction());

mealchoose = (Spinner) super.findViewById(R.id.spinner);
promt = "choose";
mealchoose.setPrompt(promt);
mealchoose.setOnItemSelectedListener(new mealReaction());

}

           private class ShopReaction implements OnItemClickListener{
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {

}
}




------ Solution ------------------------------------- -------
adapter.notefydatasetchanged () refresh list
------ eference ----------------------- ----------------
this sentence on onclick () inside ? feasible to do
------ eference -------- -------------------------------
but how are we going to modify shopAdapter array in it ?
------ eference --------------------------------------- < br> However, the method used to modify shopAdapter array in it ?   shopAdapter = new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow); This is the data inside myshow ah
------ eference - -------------------------------------
but how are we going to modify shopAdapter in arrays do ?        shopAdapter = new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow); This is the data inside myshow ah   I just want to use another array , instead myshow []; example, I now define
private CharSequence myshow2 ={"美女","香车","金钱"}
, now want the trigger event, can myshow changed myshow2
------ eference ---------------------- -----------------
but how are we going to modify shopAdapter array in it ?            shopAdapter = new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow); This is the data inside myshow ah        I just want to use another array , instead myshow []; example, I now define   
private CharSequence myshow2 ={"美女","香车","金钱"}
, now want the trigger event, can change into myshow2 myshow   shopAdapter = new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow2); further shopAdapter.notefydatasetchanged ()
------ eference --- ------------------------------------
set () method can be
--- --- eference ---------------------------------------
Will is set What method
------ eference -------------------------------------- -
but how are we going to modify shopAdapter array in it ?                shopAdapter = new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow); This is the data inside myshow ah            I just want to use another array , instead myshow []; example, I now define     
private CharSequence myshow2 ={"美女","香车","金钱"}
, now want the trigger event, can change into myshow2 myshow        shopAdapter = new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow2); further shopAdapter.notefydatasetchanged ()   put this up on what you say
public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
will appear in the error, and this method can be realized although I said features, but this way, then , there will be some waste of resources.
------ eference --------------------------------------- < br> customize a succession Adapter Adapter, update the data in the custom , this can be done only create an Adapter, click the button to update data in time is always an Adapter.
------ eference --------------------------------------- < br> set () method can be
------ eference ------------------------------- --------
ask is what set methods , could you elaborate , thank
------ eference --------------- ------------------------

I hope this problem is to construct Adapter process uses new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow); wherein myshow an array. In this case, how can the trigger button events, the adapter associated array myshow I replaced another array myshow2
------ eference --------------- ------------------------
currently not find the answer , is to find whether the substitution method is used in the constructor Adapter is not an array , use ArrayList, in the event triggered when changing the data inside the ArrayList and then call notefydatasetchanged ();

没有评论:

发表评论