[英]How to place Checkboxes with ListView (Android)
我正在关注 ListView 官方教程 - [url]http://developer.android.com/resources/tutorials/views/hello-listview.html[/url],因为我通过网络服务动态地获取条目。
问题是,我想在上面放置复选框。 我有这个
(aux (String [] aux) 在此之前已正确填写)
//setListAdapter(new ArrayAdapter<String>(this, R.layout.lista, aux));
setListAdapter(new ArrayAdapter<CheckBox>(this,R.layout.row, convertToListItem(aux)));
//ListView lv = getListView();
//lv.setTextFilterEnabled(true);
我认为问题出在我的行上。xml
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="14sp" android:typeface="normal" android:textStyle="normal"
android:layout_weight="0" android:layout_gravity="left" />
或在此 function
private List<CheckBox> convertToListItem(String[] aux2){
List<CheckBox> result = new ArrayList<CheckBox>();
ArrayList<CheckBox> boxes = new ArrayList<CheckBox>();
for (String text : aux2){
CheckBox temp = new CheckBox(this);
temp.append(text);
temp.setText(text,BufferType.NORMAL);
result.add(temp);
boxes.add(temp);
}
return result;
发生的情况是:它出现了复选框,但在前面显示的是正确的文本“android.widget.Checkbox@....”
我究竟做错了什么?
您必须实现自己的适配器扩展 ArrayAdapter 并在您的行中放置 TextView。xml
然后你必须从 getView() 方法处理你的视图。
让我知道这是否有帮助,如果没有,请您添加更多关于您需要/想要更多代码的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.