在声明实例化一个listview,并已经将数据myshow[]放入listview之中。现在想在点中listview里面某个内容之后的,更换掉listview的内容,显示另一个数组的内容。感觉这部分的操作很常用,但是好难找到这部分操作的代码或者是讲解。难道大家不是用这用方法的吗显示内容的吗?
   谢大家为我解疑,不胜荣幸。
        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) {

}
}listviewandroid

解决方案 »

  1.   

    adapter.notefydatasetchanged()刷新list
      

  2.   

    把这句话放在onclick()里?可行吗
      

  3.   

    但是用什么方法去修改shopAdapter 中的数组呢?
      

  4.   

    但是用什么方法去修改shopAdapter 中的数组呢?shopAdapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_expandable_list_item_1,this.myshow);这里面的myshow就是数据啊
      

  5.   

    但是用什么方法去修改shopAdapter 中的数组呢?shopAdapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_expandable_list_item_1,this.myshow);这里面的myshow就是数据啊我就是希望用另外一个数组,来代替myshow[];比如我现在定义了private CharSequence myshow2 ={"美女","香车","金钱"},现在想在触发事件的时候,能把myshow改变成myshow2
      

  6.   

    但是用什么方法去修改shopAdapter 中的数组呢?shopAdapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_expandable_list_item_1,this.myshow);这里面的myshow就是数据啊我就是希望用另外一个数组,来代替myshow[];比如我现在定义了private CharSequence myshow2 ={"美女","香车","金钱"},现在想在触发事件的时候,能把myshow改变成myshow2shopAdapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_expandable_list_item_1,this.myshow2);再shopAdapter.notefydatasetchanged()
      

  7.   

    但是用什么方法去修改shopAdapter 中的数组呢?shopAdapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_expandable_list_item_1,this.myshow);这里面的myshow就是数据啊我就是希望用另外一个数组,来代替myshow[];比如我现在定义了private CharSequence myshow2 ={"美女","香车","金钱"},现在想在触发事件的时候,能把myshow改变成myshow2shopAdapter = new ArrayAdapter<CharSequence>(this,android.R.layout.simple_expandable_list_item_1,this.myshow2);再shopAdapter.notefydatasetchanged()把你说的这段话放在public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {中会出现报错,而且这种方法虽然说能实现我说的功能,但是这样子的话,会出现一定浪费资源。
      

  8.   

    自定义一个Adapter继承Adapter,在自定义中更新数据,这样可以做到只创建一个Adapter,在点击按钮更新数据时候始终是一个Adapter。
      

  9.   

    请问是用什么set方法,能否详细说明一下,谢谢
      

  10.   

      我就是希望这样的,问题是构造Adapter的过程中使用了new ArrayAdapter<CharSequence>(this,android.R.layout.simple_expandable_list_item_1,this.myshow);其中myshow是一个数组。这样的话,怎么样才能在触发按钮事件之后,把adapter关联的数组myshow换成我另外一个数组myshow2
      

  11.   

    目前没有找到答案,现能找到能否代替的方法是,在构造Adapter是不用使用数组,使用ArrayList,在事件触发的时候,改变ArrayList里面的数据,然后调用notefydatasetchanged();