Whenever I change the orientation of the phone, I see that the order of the elements in the form of a grid is reversed, i.e. what was in the first position now ends, etc.
How can I get rid of this problem? Based on the clicked position, I invoke various actions. But since the order changes, incorrect actions are triggered when the screen orientation changes.
I added android:configChanges="orientation|keyboardHidden" to the manifest file.
Any help is appreciated.
Adapter Class:
class ImageAdapter extends BaseAdapter { Context mContext; private String[] mHome_icon_text = { "A", "B", "C", "D", "E","F" }; private Integer[] mHome_icon_image = { R.drawable.icon, R.drawable.icon, R.drawable.icon, R.drawable.icon, R.drawable.icon, R.drawable.icon, }; public ImageAdapter(Context c) { mContext = c; } @Override public int getCount() {
In the main class:
grid_main.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Intent i; switch (position) { case 0: // start A i = new Intent(Home.this, com.da.A.class); startActivity(i); break; case 3: //Cactivity i = new Intent(Home.this, com.da.C.class); startActivity(i); break; default: Toast .makeText(Home.this, "" + position, Toast.LENGTH_SHORT).show(); } } });
Sapan source share