這是我的ArrayAdapter:如何爲ListView編寫onClick監聽器?
public class ListArrayAdapter extends ArrayAdapter<String> {
public ArrayList<String> links = new ArrayList<String>();
public Activity activity = new Activity();
TextView linkText;
TextView linkDesc;
public Context c;
public ListArrayAdapter(Context context, int textViewResourceId,
ArrayList<String> fiokiList, Object o) {
super(context, textViewResourceId, fiokiList);
this.links = fiokiList;
activity = (Activity) (o);
c = context;
//notifyDataSetChanged();
}
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(activity, String.valueOf(position), Toast.LENGTH_LONG).show();
}
});
}
final String link = this.links.get(position);
linkText = (TextView) convertView.findViewById(R.id.linkTitle0001);
// linkImageView = (SmartImageView) convertView.findViewById(R.id.faviconView0001);
linkText.setText(link);
//ImageView imgView = (ImageView)convertView.findViewById(R.id.imageView1);
// PieMenu pieMenu = new PieMenu(imgView, activity);
//fl.addView(pieMenu);
return convertView;
}
}
我知道如何寫一個onClickListener的一個ListView的整個項目?我明白如何爲每個項目編寫一個項目,但是我不知道如何爲視圖完成這項工作?
你的意思是說,比如說,你想爲'linkText'的onClick監聽器? –
或者我認爲他意味着點擊整個'ListView'? –
我的意思是單擊列表視圖的整個項目,而不僅僅是linktext – Hick