Im pulling a list of product objects from a database call and I want to build a ListView of the data in my activity with a non-scrolling header and footer. Each row will consist of a product thumbnail, some data and a button arranged horizontally. I understand that using the ListView I can inflate each row using a separate layout.
Most of the examples Ive seen using ListView just show a simple array of strings that fill the whole view of the activity, but most real-world examples will be more complex and I can't find any good examples that explain how all these pieces fit together.
Does anyone have any pointers to sample code with a good explanation ?
An example that helped me a lot:
http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html
I hope this would be useful to you too.
private static class CustomCursorAdapter extends CursorAdapter { protected ListView mListView; protected static class RowViewHolder { public TextView mTitle; public TextView mText; } public CustomCursorAdapter(Activity activity) { super(); mListView = activity.getListView(); } @Override public void bindView(View view, Context context, Cursor cursor) { // do what you need to do } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view = View.inflate(context, R.layout.row_layout, null); RowViewHolder holder = new RowViewHolder(); holder.mTitle = (TextView) view.findViewById(R.id.Title); holder.mText = (TextView) view.findViewById(R.id.Text); holder.mTitle.setOnClickListener(mOnTitleClickListener); holder.mText.setOnClickListener(mOnTextClickListener); view.setTag(holder); return view; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With