我尝试使用复选框创建一个listView,但是当我单击列表视图时,它还会检查其他复选框 如何使我的列表视图在单击时仅选中一个复选框? 对不起noob问题,我是android编程的新手
这是我的代码:
package com.shop.browser;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import com.parse.Parse;
import com.parse.ParseQuery;
public class TechiesActivity extends Activity{
ArrayList<String> itemList;
ArrayAdapter<String> listAdapter;
ListView listView;
DataHandler handler;
ArrayList<String> dataList;
CheckBox cb;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.techies);
Parse.initialize(this, "aHxmpsFcG6t9qHuV1nVSk5uwIDcuu3iZhcLGyRqf",
"racObqmAEfJw1p6AwAiYvHJO0LqTrYHZsKfUISeY");
handler = new DataHandler();
displayView();
}
public void displayView() {
ParseQuery query = new ParseQuery("Techies");
handler.setRetrieveData(this, query, "store", "Samsung");
listAdapter = new ArrayAdapter<String>(this, R.layout.listview_format,
R.id.item_list,handler.getRetrieveData());
listView = (ListView)findViewById(R.id.listView2);
listView.setAdapter(listAdapter);
listView.setOnItemClickListener( new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
int firstPosition = listView.getFirstVisiblePosition();
for(int i = firstPosition; i < listView.getCount(); i++){
View v = listView.getChildAt(i);
if(v != null){
cb = (CheckBox)v.findViewById(R.id.cb);
cb.setChecked(true);
/**
if(cb.isChecked()){
}
**/
}
}
}
});
}
}
我可以不扩展任何适配器类,我只想继续这类可能。