我有一個自定義列表,其中每行都有一個圖像視圖和一個文本視圖以及兩個按鈕。如何知道自定義列表中單擊哪個按鈕
|```````````| 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();
}
});
但敬酒時,我按一下按鈕
檢查此http://stackoverflow.com/a/12813906/1168654 –
你可以告訴你是否希望單擊按鈕或lsitview行的偵聽器。它的混亂和不明確。 – Raghunandan