Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complex ListView example with complex data and complex layout of each row?

Tags:

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 ?

like image 927
Eno Avatar asked Feb 16 '10 18:02

Eno


2 Answers

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.

like image 113
Andy Avatar answered Oct 15 '22 10:10

Andy


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;     } } 
like image 36
sreejithmohanan Avatar answered Oct 15 '22 10:10

sreejithmohanan