即使我将两个图像放在一个列表视图项中,如何单击是否选中了哪一行上的哪个图像。请帮助解决这个问题?
问问题
106 次
1 回答
1
您可以使用列表视图的基本适配器来了解您需要什么
public class bsAdapter extends BaseAdapter
{
Activity cntx;
public bsAdapter(Activity context)
{
// TODO Auto-generated constructor stub
this.cntx=context;
}
public int getCount()
{
// TODO Auto-generated method stub
return listview_arr.length;
}
public Object getItem(int position)
{
// TODO Auto-generated method stub
return listview_arr[position];
}
public long getItemId(int position)
{
// TODO Auto-generated method stub
return name_array.length;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
View row=null;
Context context = getApplicationContext();
LayoutInflater inflater=cntx.getLayoutInflater();
row=inflater.inflate(R.layout.list_item, null);
ImageView img1 = (ImageView)row.findViewById(R.id.img1);
ImageView img2 = (ImageView)row.findViewById(R.id.img2);
img1.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
// your code is here
}
});
img2.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
// your code is here
}
});
return row;
}
}
在您的活动中将您的列表视图设置为适配器setListAdapter(new bsAdapter(this));
于 2012-12-03T07:16:59.460 回答