我想將點擊事件添加到自定義列表視圖中的兩個按鈕中。我的自定義列表視圖擴展了Base Adapter。我不知道該怎麼寫。請幫幫我 。 這裏是我的適配器代碼:我也讀過一些其他帖子,但他們不適合我。帶按鈕點擊事件的自定義列表視圖
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class CustomAdapter extends BaseAdapter {
private Activity activity;
private ArrayList data;
private static LayoutInflater inflater=null;
public Resources res;
ListModel getList = null;
int i=0;
public CustomAdapter(Activity a, ArrayList data,Resources resLocal) {
activity = a;
this.data = data;
res = resLocal;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
if(data.size() <= 0)
return 1;
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView txt_Name;
public TextView txt_Status;
public ImageButton imgbtn_senka;
public ImageButton imgbtn_fuenka;
public TableRow tblrow_status;
//public TableRow tblrow_btn;
public RelativeLayout layoutbtn;
public ImageView image;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
ViewHolder holder;
if(convertView==null){
//Inflate tabitem.xml file for each row
vi = inflater.inflate(R.layout.tabitem, null);
holder=new ViewHolder();
holder.txt_Name = (TextView)vi.findViewById(R.id.txtmemberName);
holder.txt_Status = (TextView)vi.findViewById(R.id.txtmemberStatus);
holder.image = (ImageView)vi.findViewById(R.id.imgPlayer);
holder.imgbtn_fuenka = (ImageButton) vi.findViewById(R.id.btnfusenka);
holder.imgbtn_senka = (ImageButton) vi.findViewById(R.id.btnsenka);
holder.tblrow_status = (TableRow)vi.findViewById(R.id.tblrowstatus);
holder.layoutbtn = (RelativeLayout)vi.findViewById(R.id.layoutbutton);
vi.setTag(holder);
}
else
holder=(ViewHolder)vi.getTag();
if(data.size() <= 0){
holder.txt_Name.setText("No Data");
}
else{
getList = null;
getList = (ListModel) data.get(position);
if(getList.getMemberStatus() == 3){
holder.tblrow_status.setVisibility(View.INVISIBLE);
holder.layoutbtn.setVisibility(View.VISIBLE);
if(getList.getEntry() == 0){
Log.i("abc", getList.getEntry()+"");
//holder.imgbtn_fuenka.setImageResource(res.getIdentifier("com.androidexample.customlistview:drawable/senka.png",null,null));
holder.imgbtn_senka.setImageResource(R.drawable.fusanka);
holder.imgbtn_senka.setEnabled(false);
}
}
else{
holder.tblrow_status.setVisibility(View.VISIBLE);
holder.layoutbtn.setVisibility(View.INVISIBLE);
if(getList.getEntry() == 0){
holder.txt_Status.setText("未確認");
}
else if(getList.getEntry() == 1){
holder.txt_Status.setText("參加");
}
else if(getList.getEntry() == 2){
holder.txt_Status.setText("不參加");
}
else if(getList.getEntry() == 3){
holder.txt_Status.setText("取消");
}
}
holder.txt_Name.setText(getList.getMemberName());
String url="http://10.0.2.2/football365/Photo/"+getList.getImage();
try {
Bitmap bitmap= BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
holder.image.setImageBitmap(bitmap);
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// holder.image.setImageResource(res.getIdentifier("http://10.0.2.2/football365/Photo/"+getList.getImage(),null,null));
}
return vi;
}
}
_「問題請求代碼必須展示對正在解決的問題的最小理解,包括嘗試解決方案,爲什麼他們不工作以及預期的結果。「_因此,請提供更多信息。 –