[英]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.