其实我有列表视图,在触摸列表视图中我会得到同一列表的弹出窗口。现在我想添加复选框。如何在下面的代码中添加复选框。 如果你帮我修改代码,那就太棒了。
的活动:
listView1.setAdapter(adapter);
adapter.notifyDataSetChanged();
listView1.setOnTouchListener(new AdapterView.OnTouchListener()
{
@Override
public boolean onTouch (View v, MotionEvent event){
if (event.getAction() == MotionEvent.ACTION_UP) {
dialog = new Dialog(PendingOrdersActitvity.this);
dialog.setContentView(R.layout.itembumping);
dialog.show();
list1 = (ListView) dialog.findViewById(R.id.list1);
adapter = new CustomAdapter(PendingOrdersActitvity.this, itemsList1);
list1.setAdapter(adapter);
list1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
for (int i = 0; i < itemsList1.size(); i++) {
if (i == position) {
view.setEnabled(false);
view.setClickable(false);
view.setBackgroundColor(Color.parseColor("#DCDBDB"));
adapter.notifyDataSetChanged();
ItemsBean bean = new ItemsBean();
bean.setInvNo(itemsList1.get(i).getInvNo());
bean.setItemnNameDisplay(itemsList1.get(i).getItemnNameDisplay());
bean.setLinenum(itemsList1.get(i).getLinenum());
bean.setQuantityDisplay(itemsList1.get(i).getQuantityDisplay());
bean.setProdnum(itemsList1.get(i).getProdnum());
newListitems.add(bean);
}
}
insertintodatabase(newListitems);
newListitems.clear();
return true;
}
}
}
}
答案 0 :(得分:0)
试试这个:
修改类CustomAdapter,
一个。添加字段和方法,
class CustomAdapter...{
boolean mInDialog = false;
.
.
.
public void showCheckbox(boolean flag){
mInDialog = true
}
}
湾修改getView(),
CheckBox cb = (CheckBox) convertView.findViewById(R.id.checkbox);
if(mInDialog){
cb.setVisibility(View.VISIBLE);
}else{
cb.setVisibility(View.GONE);
}
修改活动,在“list1.setAdapter(adpter)”之前添加:
adapter.showCheckbox(true);
当对话框被解除时,请添加:
adpater.showCheckbox(false);
adapter.notifyDataSetChanged();
希望这有帮助!