实际上我有一个列表,通过单击列表中的项目,它将通过选择弹出窗口中的项目来显示弹出窗口,我已经禁用或删除了主背景列表中的项目。我是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;
发布于 2016-11-07 12:15:40
当点击列表中的项目时,创建预警对话框,在预警对话框中,点击是删除该列表项,创建列表自定义适配器,创建删除函数删除该列表项,然后在预警对话框选项中调用该函数。
第一步:编写函数删除适配器中的项
步骤2:为适配器创建对象,并在对话框积极响应中调用删除函数。
https://stackoverflow.com/questions/40464844
复制