back button android

Posted by Raogrimm on Stack Overflow See other posts from Stack Overflow or by Raogrimm
Published on 2012-11-10T22:42:26Z Indexed on 2012/11/10 23:00 UTC
Read the original article Hit count: 214

Filed under:
|

i am having trouble implementing the back button properly. all of the code snippets i have seen have not worked for me. what i am trying to do when i press the back button is just go back to the previous list. pretty much i have a list within a list and i just want it to go back to the previous list. how would i go about doing this? this is the list i have, every item has a separate list that it has. lets say you click on weapons, you then get a list of different weapon types and so on

final String[] weapons = getResources().getStringArray(R.array.weapons);
                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, weapons));
                lv.setOnItemClickListener(new OnItemClickListener() 
                {
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) 
                    {
                        System.out.println("item clicked: "+weapons[position]);
                        switch(position)
                        {
                            case 0:
                                final String[] axes = getResources().getStringArray(R.array.axes);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, axes));
                                break;
                            case 1:
                                final String[] clubs = getResources().getStringArray(R.array.clubs);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, clubs));
                                break;
                            case 2:
                                final String[] daggers = getResources().getStringArray(R.array.daggers);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, daggers));
                                break;
                            case 3:
                                final String[] great_axes = getResources().getStringArray(R.array.great_axes);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, great_axes));
                                break;
                            case 4:
                                final String[] great_katana = getResources().getStringArray(R.array.great_katana);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, great_katana));
                                break;
                            case 5:
                                final String[] great_swords = getResources().getStringArray(R.array.great_swords);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, great_swords));
                                break;
                            case 6:
                                final String[] hand_to_hand = getResources().getStringArray(R.array.hand_to_hand);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, hand_to_hand));
                                break;
                            case 7:
                                final String[] katana = getResources().getStringArray(R.array.katana);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, katana));
                                break;
                            case 8:
                                final String[] polearms = getResources().getStringArray(R.array.polearms);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, polearms));
                                break;
                            case 9:
                                final String[] scythes = getResources().getStringArray(R.array.scythes);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, scythes));
                                break;
                            case 10:
                                final String[] staves = getResources().getStringArray(R.array.staves);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, staves));
                                break;
                            case 11:
                                final String[] swords = getResources().getStringArray(R.array.swords);
                                setListAdapter(new ArrayAdapter<String>(ffxidirectory.this, R.layout.list_item, swords));
                                break;
                        }
                    }
                });

© Stack Overflow or respective owner

Related posts about android

Related posts about back-button