Le tableau est défini au niveau de la classe.
Ce sont mes méthodes SavedInstance: mais toujours, lorsque je change d'orientation, le tableau est vide p> p>
3 Réponses :
Lorsque vous utilisez onrestoreInstancestate () code> pour restaurer l'état, son appelé après
Onstart () Code> Vous devez donc mettre à jour votre liste avec l'état enregistré après avoir défini votre adaptateur. Votre meilleure option consiste à restaurer la liste dans
Oncreate () code> de la même manière que vous le faites sur
onrestoreInstancestate () code>. Vous pouvez également redéfinir l'adaptateur ou appeler
notifyDatastetchangeed () code>. P>
TextView textviewname; String textname; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //declare the ui like this textviewname = (TextView) findViewById(R.id.textviewid); if(savedInstanceState==null){ //the first time the activity was created //do the normal flow of the code //Example:getting the intent data for(savedList)or processing it Intent i = getIntent(); textname = i.getStringExtra("savetext"); //or textname="name_data"; }else{ //this is called when orientation change occur //get the savedata list=savedInstanceState.getStringArrayList("savedList"); textname=savedInstanceState.getString("savetext"); } textviewname.setText(textname); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); //saving data when orientation change trigger //saving data before ondestroy happens //onSaveInstanceState is called before going to another activity or orientation change outState.putStringArrayList("savedList", list); outState.putString("savetext", textname); //all imnportant data saved and can be restored } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); //this is only called after ondestroy-> oncreate occur list=savedInstanceState.getStringArrayList("savedList"); textname=savedInstanceState.getString("savetext"); //oncreate->onSaveInstanceState->ondestroy->oncreate->onRestoreInstanceState }
Essayez d'utiliser à la place p>
Stackoverflow.com/a/4967491/1001401 Essayez d'obtenir votre arraylist à Oncreate (Bundle SavedInstancestate) de SavedInstanCetate