实际上我通过单击列表中的项目有一个列表,它将通过选择弹出窗口中的项目获得弹出窗口我已禁用或删除主背景列表中的项目。我是新来的android请帮帮我。
主要活动:
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
newListitems2.clear();
newListitems2.addAll(itemsList1);
dialog = new Dialog(PendingOrdersActitvity.this);
dialog.setContentView(R.layout.itembumping);
dialog.show();
listView1.setTag(position);
list1=(ListView )dialog.findViewById(R.id.list1);
ItemBumpingAdapter adapter2 = new ItemBumpingAdapter(PendingOrdersActitvity.this,newListitems2);
list1.setAdapter(adapter2);
Button okButton = (Button)dialog.findViewById(R.id.ok1);
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
Button cancelButton = (Button)dialog.findViewById(R.id.Cancel1);
cancelButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
后台列表适配器:
public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
ViewHolder holder;
String item = null, qty = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflator.inflate(R.layout.itembumpingadapter, null);
holder.qty = (TextView) convertView.findViewById(R.id.qty);
holder.name = (TextView) convertView.findViewById(R.id.item);
holder.childText = (TextView) convertView
.findViewById(R.id.childitem);
holder.qtyChild = (TextView) convertView
.findViewById(R.id.qtychild);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.chckbox1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
parentobjid=newListitems.get(position).getParentobjectid();
if(!parentobjid.isEmpty())
{
holder.name.setText(" " +newListitems.get(position).getItemnNameDisplay());
holder.name.setTextColor(Color.parseColor("#CC0000"));
holder.qty.setText(" "+String.valueOf(newListitems.get(position)
.getQuantityDisplay()));
holder.qty.setTextColor(Color.parseColor("#CC0000"));
}
else
{
holder.name.setText(newListitems.get(position).getItemnNameDisplay()); holder.qty.setText(String.valueOf(newListitems.get(position)
.getQuantityDisplay()));
holder.name.setTextColor(Color.parseColor("#FFFFFF")); holder.qty.setTextColor(Color.parseColor("#FFFFFF"));
对话框列表适配器:
if (convertView == null) {
holder = new ViewHolder();
convertView = inflator.inflate(R.layout.itembumpingadapter, null);
holder.qty = (TextView) convertView.findViewById(R.id.qty);
holder.name = (TextView) convertView.findViewById(R.id.item);
holder.childText = (TextView) convertView
.findViewById(R.id.childitem);
holder.qtyChild = (TextView) convertView
.findViewById(R.id.qtychild);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.chckbox1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
parentobjid=newListitems.get(position).getParentobjectid();
if(!parentobjid.isEmpty())
{
holder.name.setText(" " +newListitems.get(position).getItemnNameDisplay());
holder.name.setTextColor(Color.parseColor("#CC0000"));
holder.qty.setText(" "+String.valueOf(newListitems.get(position)
.getQuantityDisplay()));
holder.qty.setTextColor(Color.parseColor("#CC0000"));
}
else
{
holder.name.setText(newListitems.get(position).getItemnNameDisplay());
holder.qty.setText(String.valueOf(newListitems.get(position)
.getQuantityDisplay()));
holder.name.setTextColor(Color.parseColor("#FFFFFF"));
holder.qty.setTextColor(Color.parseColor("#FFFFFF"));
holder.checkbox.setChecked(false);
holder.checkbox.setTag(position);
holder.checkbox.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int pos=(Integer) v.getTag();//Cast object to integer
newListitems.get(pos).setChecked(!newListitems.get(pos).isChecked());
}
});
if(newListitems.get(position).isChecked()){
holder.name.setEnabled(true);
holder.name.setBackgroundColor(Color.parseColor("#DCDBDB"));
}else{
holder.name.setEnabled(false);
}
}
return convertView;
答案 0 :(得分:0)
单击列表中的项目时,创建警报对话框, 在警报对话框中,单击是删除该列表项,为列表创建自定义适配器并创建删除功能以删除列表项,然后在警报对话框选项中调用该功能。
步骤1:写入功能以删除适配器中的项目
步骤2:为适配器创建对象,并在对话框中重新调用该删除功能。