Android ListView更改应发生在restoreInstanceState上

时间:2013-10-14 14:06:44

标签: android listview

嘿我想在ListView中进行更改,就像listview中TextView上的textchange一样。但这应该不会发生在ItemClick它应该发生在restoreInstance状态任何帮助将在这里是赞赏我的代码

 @Override
    public void onRestoreInstanceState(Bundle savedInstanceState){
        super.onRestoreInstanceState(savedInstanceState);

   View v1 = inventoryList.getChildAt(2); 
            if(v1 != null){
            TextView tx = (TextView) v1.findViewById(R.id.txt_location);
                   tx.setText("why does this not work");

                   }

    }

1 个答案:

答案 0 :(得分:0)

在对notifyDataSetChanged()

进行更改后,您需要调用适配器的ListView方法
@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
    super.onRestoreInstanceState(savedInstanceState);

     View v1 = inventoryList.getChildAt(2); 
        if(v1 != null){
               TextView tx = (TextView) v1.findViewById(R.id.txt_location);
               tx.setText("why does this not work");

               // You're missing this
               inventoryList.getAdapter().notifyDataSetChanged();

               // Or simply call  
               // adapter.notifyDataSetChanged(); // if you maintain a reference to the adapter
         }

}