I am trying to click on a list entry. My List is a custom list view, with the data pulled from an ArrayAdapter. The list shows 3 parts of the Array entry, and a picture, but i want to send those items and the rest of the array entry to the next activity to show more information about the selected item.
Below is my Class with the Adapter in it. You will see a commented section /** **/ that i have been trying to figure out how to putExtra these items, but i just can't seem to figure it out. Each Book has 12 attributes to them, but only 4 are shown in the listView prior to clicking for more information.
I am using a Viewholder, so i am not sure i that is affecting me or not, but i do plan on having a fairly long list in the listview before the item click.
public class Novels extends ListActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
setListAdapter(new NovelAdapter(this, R.layout.list_item, NovelsStore.getNovels()));
getActionBar().setDisplayHomeAsUpEnabled(true);
}
public Novels() {
}
public class NovelAdapter extends ArrayAdapter<Book> {
LayoutInflater layoutInflater;
public NovelAdapter(Context context, int textViewResourceId, List<Book> novels) {
super(context, textViewResourceId, novels);
layoutInflater = LayoutInflater.from(context);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent){
ViewHolder holder;
Book novels = getItem(position);
// if no references in the view
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.list_item, null);
// put them into a holder
holder = new ViewHolder();
holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
holder.tvSeries = (TextView) convertView.findViewById(R.id.tvSeries);
holder.tvEra = (TextView) convertView.findViewById(R.id.tvEra);
holder.ivBookImage = (ImageView) convertView.findViewById(R.id.ivBookImage);
//set the view tag
convertView.setTag(holder);
} else {
// in case we have a recycled view, just get the Tag
holder = (ViewHolder) convertView.getTag();
}
//Assign Property to the TextViews
holder.tvTitle.setText(novels.getTitle());
holder.tvSeries.setText(novels.getSeries());
holder.tvEra.setText(novels.getEra());
holder.ivBookImage.setImageResource(novels.getBookImage());
return convertView;
}
public class ViewHolder {
public TextView tvTitle;
public TextView tvSeries;
public TextView tvEra;
public ImageView ivBookImage;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// If app icon in the action bar gets clicked; go back
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Any help on this would be great!