0

嘿,我希望在 ListView 中发生更改,例如列表视图中 TextView 上的文本更改。但这不应该在 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");

                   }

    }
4

1 回答 1

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
         }

}
于 2013-10-14T15:37:26.473 回答