我想了解如何通过单击ListView
中的单选按钮来接收通知,但当单击ListView
项目旁边的单选按钮时没有任何回应。以下是我设置侦听器的代码。我在onPostExecute()
方法下的异步任务中执行此操作,我从服务器填充我的ListView
,而我的主要活动扩展为MapActivity
。有谁知道我做错了什么?无法获取所选ListView项目
protected void onPostExecute(ArrayList<String> result) {
// ... some code
mapView.postInvalidate();
final ArrayAdapter<String> arrayAdpt = new ArrayAdapter<String>(
getApplicationContext(), android.R.layout.simple_list_item_single_choice,
viewline);
ListView restaurant_list = (ListView) findViewById(R.id.list);
restaurant_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
restaurant_list.setAdapter(arrayAdpt);
restaurant_list.setScrollContainer(true);
restaurant_list.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Log.e("listargs", (String.valueOf(arg1)) + " " + String.valueOf(arg3));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
请尝试onItemClickListener。 – 2013-03-12 16:57:55
匆匆一瞥,我不确定是否需要为ListView替换ListItem的onItemSelectedListener,以及ListView的onItemClickListener(到目前为止)。您还可以为RadioButton设置一个监听器。但是,当然,这对于哪个区域会触摸敏感区域有很大不同。 – 2013-03-12 17:05:05