dejar de recargar ListView en cambio de orientación en android
Frecuentes
Visto 1,193 veces
0
Tengo un ListView
, populated from a XML. Everything is working fine, but when i change my device's orientation(Portrait<-->Landscape) it reloads the ListView
. I want to stop it. I have used onSaveInstanceState
y onConfigurationChanged
. But it still reloads.
Aquí está mi código:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
alrowDataView = savedInstanceState.getParcelableArrayList("name");
// Toast.makeText(MainActivity.this,alrowDataView.size() , Toast.LENGTH_LONG).show();
// lvrowDataView=(ListView) findViewById(R.id.list_xml);
}
else{
Toast.makeText(MainActivity.this,"NOdata" , Toast.LENGTH_LONG).show();
setContentView(R.layout.activity_main);
lvrowDataView = (ListView) findViewById(R.id.list_xml);
ParsingXml parsing = new ParsingXml();
After that general ListView operations...
y aquí está el código para OnSavedInstanceState
y onConfigurationChanged
.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(MainActivity.this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
Toast.makeText(MainActivity.this, "portrait", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putParcelableArrayList("name", alrowDataView);
//Toast.makeText(MainActivity.this, alrowDataView.size(),Toast.LENGTH_LONG).show();
}
and these are the declarations
private ListView lvrowDataView;
private ArrayList<RowData> alrowDataView;
RowDataAdapter adapterRowData;
No quiero usar android:configChanges="orientation"
También en onSaveInstanceState
the ArrayListis null!!!
1 Respuestas
1
Prueba de esta manera
android:configChanges="orientation"
Is not working with latest android api 3.0+
You need to use like this
<activity
android:name="YourActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
/>
Respondido el 25 de Septiembre de 13 a las 10:09
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas android listview android-orientation or haz tu propia pregunta.
So, what is your reason for not wanting to use
configChanges
en tu manifiesto? - tolgapwell firstly it is not working,i have tried it!then it is just a demo!in the real one,there will be some other activity which i need to be refreshed.Thats why.I didn't knew that before. - user2605103