Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make your own adapter:</p> <p>BaseAdapter already provieds methods for working with different View types (different layout for list item cells) and to effektivly recycle views:</p> <ul> <li>getViewTypeCount(): The count of how many different Views (layouts) are present. </li> <li><p>getItemViewType(): Returns a integer to identify the view type of the item in the cell. Note the internally BaseAdapter implementation uses an array. Therefore your values returned here must be from 0 to n. You are not allowed to skip indexes.</p> <p>public class MyAdapter extends BaseAdapter {</p> <pre><code>private final int VIEW_TYPE_NORMAL = 0; private final int VIEW_TYPE_4_TEXTS = 1; /** * The inflater for */ protected LayoutInflater inflater; protected Context context; public MyAdapter(Context context) { this.context = context; this.inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getViewTypeCount() { // There are two view types return 2; } @Override public int getItemViewType(int position) { if (position == 0) return VIEW_TYPE_4_TEXTS; else return VIEW_TYPE_NORMAL; } @Override public View getView(int position, View convertView, ViewGroup parent) { int type = getItemViewType(position); if (convertView == null) { convertView = newView(type, parent); } bindView(position, type, convertView); return convertView; } @Override public long getItemId(int position) { return 0; // replace it with your id, if you have stable ids in your // adapter } /** Inflates the correct view accorind the view type **/ public View newView(int type, ViewGroup parent) { if (VIEW_TYPE_4_TEXTS == type) { View view = inflater.inflate(R.layout.your_layout_with_4_textviews, parent, false); view.setTag(new ViewHolder4TextViews(view)); // ViewHolder pattern return view; } // Otherwise its a normal item with VIEW_TYPE_NORMAL View view = inflater .inflate(R.layout.your_normal_layout, parent, false); view.setTag(new NormalViewHolder(view)); // ViewHolder pattern return view; } /** Bind the data for the specified {@code position} to the {@code view}. */ public void bindView(int position, int type, View view) { if (VIEW_TYPE_4_TEXTS == type) { // set the 4 text view values ViewHolder4TextViews holder = (ViewHolder4TextViews) view.getTag(); holder.textview1.setText("..."); holder.textview2.setText("..."); holder.textview3.setText("..."); holder.textview4.setText("..."); } else { // VIEW_TYPE_NORMAL NormalViewHolder holder = (NormalViewHolder) view.getTag(); holder.textview.setText("..."); } } </code></pre> <p>}</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload