我如何从onItemClick调用android中的onListItemClick方法

时间:2012-11-21 12:48:03

标签: android listview

我有一个按钮和一个列表视图。我按照列表中的一个列表视图在一个列表视图中设置了三个适配器,但是当我按下后退按钮时,它只会点击一次。

代码在这里:

public class GamesFragment extends ListFragment{

    Context context;

    Dialog dialog;
    Game_Adapter gameadapter; 
    Game_Channels_Sections_Adapter  GameChannelsSections;   
    Game_Sections_Details_Adapter  GameSectionsDetails;

    ListView listView1;
    JSONArray dataJsonObject;
    Button back,back2;
    TextView title;
    Button add;
      int i=0;
      int y=0;
      int z=0;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.game_list, container,false);
        listView1=(ListView)view.findViewById(android.R.id.list);
        back=(Button) view.findViewById(R.id.button_back);

        GamesFragmentData dataobserver=new GamesFragmentData();
        add=(Button) view.findViewById(R.id.button_add);
        title=(TextView) view.findViewById(R.id.textview_caption);
        title.setText("Games");

        add.setVisibility(View.INVISIBLE);
        ServerManager.getInstance().addObserver(dataobserver);

        ServerManager.getInstance().readLoopForGameData(AppConstances.Games_Channels);
        if(gameadapter==null)
            gameadapter=new Game_Adapter(getActivity(), new JSONArray());
        listView1.setAdapter(gameadapter);


        Log.e("","In ongameadapter---->");
        return view;
    }


    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {

        System.out.println("In onListItemClick---->");

        Log.e("","In onListItemClick---->");
        ServerManager.getInstance().readLoopForGame_Channels_Sections_Data(AppConstances.Games_Channels_Sections);

        GameChannelsSections=new Game_Channels_Sections_Adapter(getActivity(),new JSONArray());


        listView1.setAdapter(GameChannelsSections);

        back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Log.e("","In onListItemClick1---->");
                listView1.setAdapter(gameadapter);


            }
        });


        listView1.setOnItemClickListener(new OnItemClickListener() {


            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int position,
                    long id) {


                ServerManager.getInstance().readLoopForGame_Channels_Sections_Details_Data(AppConstances.Games_Sections_Details);

            GameSectionsDetails=new Game_Sections_Details_Adapter(getActivity(),new JSONArray());
                listView1.setAdapter(GameSectionsDetails);
            }
                Log.e("","In onItemClick---->");
                back.setOnClickListener(new OnClickListener() {


                    @Override
                    public void onClick(View v) {



                        Log.e("","In onItemClick1---->");
                        listView1.setAdapter(GameChannelsSections); 



                    }
                });

            }
        });


        super.onListItemClick(l, v, position, id);   
    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);

    }

代码有两种方法:
onListItemClick onItemClick

当我点击列表视图控件时,它会从 onListItemClick 转到 onItemClick ,因为我在onclick上的单个列表视图中设置了三个适配器。
但是当我点击后退按钮时,我需要收回。我不能回去。

说,如果我按下适配器1,我设置适配器2并且如果我按下适配器2,我已经设置了适配器3.

现在,我在适配器3.点击后退按钮,我从3回到2,但我不能从2到1。

简而言之,如何从onItemClick控制回onListItemClick以便可以重复点击流程?

0 个答案:

没有答案