2010-10-23 43 views
0

我在Android中有一个单选按钮组,我用数据库中的数据填充。为了获取数据旁边我已经使用了ListAdapter每个单选按钮显示:单选按钮点击不在ListView内注册

String[] columns = new String[] {DataHelper.KEY_WORD, DataHelper.KEY_ALT1 , DataHelper.KEY_ALT2 ,DataHelper.KEY_ALT3 ,DataHelper.KEY_ALT4 }; 
      // the XML defined views which the data will be bound to 
      int[] to = new int[] { R.id.word, R.id.q1, R.id.q2, R.id.q3 , R.id.q4 }; 

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.game, c, columns, to); 
this.setListAdapter(mAdapter); 

为了获得ListAdapter工作,我需要一个列表视图,但列表视图似乎禁用我OnClickListener。

我该如何解决这个问题?反正有没有使用listview来填充radiogroup,或者让onClickListener保持活跃状态​​的方法?

回答

0

您必须使用Android ListView提供的复选框/单选按钮机制。你不能在ListView中自己实现点击监听器。

看看ListView.getCheckedItemPosition上手: http://developer.android.com/reference/android/widget/ListView.html#getCheckedItemPosition()

+0

大家好,感谢您的答复。我已经尝试添加ListView lv = this.getListView(); this.getListAdapter(); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lv.setItemsCanFocus(true); lv.setOnClickListener(rq_listener);这是一个正确的思考方式吗? rq_listener是我在从数据库导入数据之前用于单选按钮的那个,当我将它添加到setOnClickListener时,该活动将不会启动。 – kakka47 2010-10-23 13:51:50

+0

我不认为我已经理解了我应该怎么想,所有的动作都应该在列表视图上,然后传递给单选按钮?我怎样才能使用从GetItemCheckedPosition返回的结果?很抱歉,很多问题,是新手! – kakka47 2010-10-23 13:53:24