我有列表视图。为此,我将每一行自定义为文本视图和复选框。现在我想获取选中项目的名称。我尝试使用 checkedItemPositons 但那不起作用是因为 2 个布局?
我想在按下删除按钮时删除选中的项目。我该怎么做?这是我的代码
public class ManageLikes extends Activity implements OnClickListener {
ListView lv;
Button btndelsel, btndelall;
CheckBox chk;
HashMap<Integer, Boolean> mCartItems = new HashMap<Integer, Boolean>();
List<String> likes = new ArrayList<String>();
//DatabaseHandler db = new DatabaseHandler(getApplicationContext());
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.managelikes);
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
//String data[] = { "a", "b", "c", "d", "e"};
likes = db.getAllLikes();
lv = (ListView) findViewById(R.id.listView);
btndelsel = (Button) findViewById(R.id.btndelsel);
btndelall = (Button) findViewById(R.id.btndelall);
btndelsel.setOnClickListener(this);
btndelall.setOnClickListener(this);
lv.setCacheColorHint(0);
LayoutInflater mLInflater = getLayoutInflater();
final LAdapter adapter = new LAdapter(getApplicationContext(),likes, mLInflater);
lv.setAdapter(adapter);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int count = likes.size();
String checked = "";
if (v == btndelsel) {
//i want delete the checked items here
}
if (v == btndelall) {
//delete all items
}
}
}