0
我爲自己的listview
自定義ArrayAdapter
類。我們可以添加自定義ArrayAdpater類的監聽器
我正在使用那個自定義適配器更多listviews
。
所有listview
項目必須在點擊時開始相同的活動,如何做到這一點,而不需要爲每個listview
項目添加單獨的itemlistener?
我做了這樣的事情:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)(context.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
row = inflater.inflate(layoutResourceId, parent, false);
ImageView albumArt = (ImageView)(row.findViewById(R.id.album_art));
TextView albumName = (TextView)(row.findViewById(R.id.album_name));
final OnClickListener Listener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), PlayerActivity.class);
intent.putExtra("albumart", album.albumArt);
v.getContext().startActivity(intent);
}
};
row.setOnClickListener(Listener);
}
任何建議嗎?