I now have a listview using simplecursoradapter to get data from the database and I query a link from the database and assign it to a button in each row of the list and I am rewriting the simplecursoradapter class to set onclicklistener for the button, but my codes aren't working, would anyone tell me what's the problem? thx
this is my Adapter
public class ChannelAdapter extends SimpleCursorAdapter{
private LayoutInflater mInflater;
private List<ChannelPoster> items;
private Context mContext;
private String dblink;
public ChannelAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position,View convertView,ViewGroup par)
{
ViewHolder holder;
if(convertView == null)
{
convertView = mInflater.inflate(R.layout.channelview, null);
holder = new ViewHolder();
holder.image = (ImageView) convertView.findViewById(R.id.poster);
holder.text = (TextView) convertView.findViewById(R.id.channel);
holder.button = (ImageButton) convertView.findViewById(R.id.douban);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
ChannelPoster tmpN=(ChannelPoster)items.get(position);
holder.text.setText(tmpN.getChannel());
holder.image.setImageResource(tmpN.getPoster());
holder.button.setOnClickListener(new ImageButton.OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(mContext, Doubanframe.class);
Bundle bunde = new Bundle();
bunde.putString("dblink",dblink);
intent.putExtras(bunde);
mContext.startActivity(intent);
}
});
return convertView;
}
private class ViewHolder
{
ImageView image;
TextView text;
ImageButton button;
}
}
and this is how I populate the listview
mDB = new ChannelDB(this);
String[] columns = {mDB.KEY_ID, mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_PATH, mDB.KEY_DBLINK};
String table = mDB.channelS_TABLE;
c = mDB.getHandle().query(table, columns, null, null, null, null, null);
startManagingCursor(c);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.channelview,
c,
new String[] {mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_DBLINK},
new int[] { R.id.poster, R.id.channel, R.id.douban});
channellist.setAdapter(adapter);