ListView动态添加Button
2015-08-21 本文已影响345人
shadyfeng
本身有onClick事件的控件需设置android:focusable="false"属性,图中删除事件为imageView本身不含onClick事件.以下代码百度得来
public class AccountsAdapter extends BaseAdapter
{
private List<LoginReq> list = new ArrayList<LoginReq>();
private Context context;
ViewHolder holder;
public AccountsAdapter(Context context,
List<LoginReq> list)
{
this.context = context;
this.list = list;
}
@Override
public int getCount()
{
return list.size();
}
@Override
public Object getItem(int position)
{
return list.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
holder = null;
if (convertView == null)
{
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(
R.layout.option_item, null);
holder.textView = (TextView) convertView
.findViewById(R.id.item_text);
holder.imageView = (ImageView) convertView
.findViewById(R.id.delImage);
holder.acountLayout = (RelativeLayout) convertView
.findViewById(R.id.account_rl);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(list.get(position).getName());
holder.textView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
}
});
holder.imageView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
}
});
return convertView;
}
private class ViewHolder
{
private TextView textView;
private ImageView imageView;
}
QQ截图20150821201756.png