android listview button和EditText

点击按钮 让listview 所有edittext 显示可编辑,并显示删除按钮

if(null!=dataList && 0<dataList.size()){
				for(int i=0;i<dataList.size();i++)
				{
					view=listView.getChildAt(i);
					EditText edittxt=(EditText)view.findViewById(R.id.txt_number);
					Button btnprice=(Button)view.findViewById(R.id.btn_price);
					if(null!=edittxt)
					{
						edittxt.setEnabled(true);
					}
					if(null!=btnprice)
					{
						btnprice.setVisibility(View.VISIBLE);
					}
				}
			}

  第二步重写adapter 在getView设置button事件

holder.btdel.setTag(position);
		holder.btdel.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				views=v;
				// TODO Auto-generated method stub
				new AlertDialog.Builder(context)
				.setTitle("提示")
				.setMessage("确认要删除吗?")
				.setPositiveButton("确定",new DialogInterface.OnClickListener() {					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						listdata.remove(listdata.get(Integer.valueOf(views.getTag().toString()))); 
						notifyDataSetChanged();
					}
				}).setNegativeButton("取消", new DialogInterface.OnClickListener() {					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						dialog.dismiss();
					}
				}).show();
				
			}
		});

  

posted on 2012-03-29 18:39  freexiaoyu  阅读(1857)  评论(0编辑  收藏  举报