Sunday, April 20, 2014

How to replace the contents of the listview


In a statement to instantiate a listview, and have the data myshow [] being placed in listview. Now want to listview inside a content point later, replace the lost listview contents, display the contents of another array. This part of the operation feeling very common, but hard to find in this part of the operation code or explain. Do we not use this method you use to display the contents of it?
Thank you very much for my eliminating, be honored.



 
public class MainActivity extends Activity {
private CharSequence myshow [] = {"Happy Camp", "O mind fast food", "big bowl of rice"};
private Spinner mealchoose = null;
private ListView showList = null;
private CharSequence promt = null;
ArrayAdapter 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 (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) {

}
}



<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
adapter.notefydatasetchanged () to refresh the list
Reply:
cited a floor yuebanmumu reply:
adapter.notefydatasetchanged () to refresh the list
this sentence on onclick () in ? feasible yet
Reply:
cited a floor yuebanmumu reply:
adapter.notefydatasetchanged () to refresh the list
But how are we going to modify the array shopAdapter it?
Reply:
reference to the third floor kklt21cn reply:
Quote: references to a floor yuebanmumu reply:

adapter.notefydatasetchanged () to refresh the list
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
Reply:
references, 4th Floor yuebanmumu reply:
Quote: references to the third floor kklt21cn reply:

Quote: references to a floor yuebanmumu reply:

adapter.notefydatasetchanged () to refresh the list
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 = {"beauty", "Dream Car", "money"} 
, and now want to at the time of the triggering event, can change into myshow2 myshow
Reply:
references, 5th Floor kklt21cn reply:
Quote: references to the 4th floor yuebanmumu reply:

Quote: references to the third floor kklt21cn reply:

Quote: references to a floor yuebanmumu reply:

adapter.notefydatasetchanged () to refresh the list
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 = {"beauty", "Dream Car", "money"} 
, and now want to at the time of the triggering event, can myshow changed myshow2
shopAdapter = new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow2); then shopAdapter.notefydatasetchanged ()
Reply:
set () method can be
Reply:
reference to the 7th floor pibaijun0001 reply:
set () method can
May I ask what is set
Reply:
reference to the 6th floor yuebanmumu reply:
Quote: references, 5th Floor kklt21cn reply:

Quote: references to the 4th floor yuebanmumu reply:

Quote: references to the third floor kklt21cn reply:

Quote: references to a floor yuebanmumu reply:

adapter.notefydatasetchanged () to refresh the list
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 = {"beauty", "Dream Car", "money"} 
, and now want to at the time of the triggering event, can myshow changed myshow2
shopAdapter = new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow2); then shopAdapter.notefydatasetchanged () < / blockquote>
put you say these words on
 public void onItemClick (AdapterView  parent, View view, int position, 
long id) {
will appear in the error, and although this method can achieve the functions I say, but this way, then, there will be some waste of resources.
Reply:
A custom Adapter inherit Adapter, update the data in the custom, this can be done only create an Adapter, click the button to update the data in time is always an Adapter.
Reply:
set () method can be
Reply:
reference to the 11th floor qxyjj reply:
set () method can
what is the set method, the ability to elaborate Thank you
Reply:
reference to the 10th floor u011565429 reply:
inherit a custom Adapter Adapter, update the data in the custom, this can be done only create an Adapter, clicking button to update the data is always a time Adapter.

I hope this question is in the process of constructing Adapter uses the new ArrayAdapter (this, android.R.layout.simple_expandable_list_item_1, this.myshow); which myshow is an array. In this case, how can the event after the trigger button, the associated array myshow adapter replace me another array myshow2
Reply:
No answer can now be able to find ways to replace that in the constructor Adapter is not using an array, use ArrayList, when the event is triggered, changing ArrayList data inside, then call notefydatasetchanged ();

No comments:

Post a Comment