我有一个按钮和一个列表视图。我根据单击列表在一个列表视图中设置三个适配器,但是当我按下返回按钮时,它只会单击一次。
代码在这里:
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 以便可以重复点击流程?