我有一个自定义列表,其中每行有一个图像视图,一个文本视图和两个按钮。
|```````````| text box
|Image View |
|___________| Button1 Button2
这是一行列表的布局。 我的自定义AdapterClass是..
public class sublist extends ArrayAdapter<String> {
private final Activity context;
private final Vector<String> shortDisJornals;
private final Vector<String> imageId1;
public sublist(Activity context, Vector<String> s1,
Vector<String> imageId1) {
super(context, R.layout.sublist, s1);
this.context = context;
this.shortDisJornals = s1;
this.imageId1 = imageId1;
Log.d("image vector", ""+imageId1);
}
@Override
public View getView(final int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.sublist, null, true);
TextView txtTitle = (TextView) rowView
.findViewById(R.id.textViewjurnals);
ImageView imageView = (ImageView) rowView
.findViewById(R.id.imageViewJurnals);
Button buyJurnals=(Button)rowView.findViewById(R.id.buttonjurnalsBuy);
buyJurnals.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getContext(), "sdsd"+position, 3000).show();
}
});
Button detailsJurnalis=(Button)rowView.findViewById(R.id.buttonjrnalsDetails);
txtTitle.setText(shortDisJornals.elementAt(position));
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
String image = imageId1.elementAt(position);
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
image).getContent());
imageView.setImageBitmap(null);
imageView.setImageBitmap(bitmap);
// setContentView(image);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch(Exception e){}
return rowView;
}
}
现在在我的主要活动中 -
lv = (ListView) findViewById(R.id.listView1);
titleVector = new Vector<String>();
imageUrl = new Vector<String>();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
Toast.makeText(getApplicationContext(), "sd", 3000).show();
}
});
但是当我点击按钮时,吐司剂量不显示
答案 0 :(得分:0)
您正在为其中一个按钮设置onClickListener:buttonjurnalsBuy。单击此按钮应该可以工作。只需为另一个Button设置另一个Listener即可处理此按钮的点击。
如果单击列表中的整行,则会调用您在setOnItemClickListener中设置的侦听器。
如果为某些视图和OnItemClickListener设置单独的单击侦听器,则在用户单击其中一个视图时将调用单击侦听器。如果用户单击行中的其他位置,将调用OnItemClickListener。