0

Once I write a ListView demo, the ListView's items have some different types.

item1:

Text

Pic Pic Pic

Pic Pic Pic

item2:

Text

Pic Pic

Pic Pic

item3:

Text

Pic Pic Pic

Pic Pic Pic

Pic Pic Pic

...

So I override the getViewTypeCount() and getItemViewType().It work well. But Now I change to use RecyclerView. Is there a better solution?Please help me.

Egos Zhang
  • 1,334
  • 10
  • 18

2 Answers2

0

use

getItemCount() {
//pojo class array size
 return mDataset.size();
}
impathuri
  • 574
  • 6
  • 21
  • please upvote if u like this , call your array of pojo class and get instance of it and count by size private ArrayList mDataset; in your Adapterclass – impathuri Sep 30 '15 at 08:06
  • You might misunderstand what I mean. – Egos Zhang Sep 30 '15 at 08:12
  • Could you explain your code? Code-only answers are generally not acceptable on StackOverflow, and as such are liable to be deleted. – Wai Ha Lee Oct 01 '15 at 00:49
  • @RajeshJadav the question asked by him was how to get item from the list so based on the question i have passed – impathuri Oct 01 '15 at 05:19
0

This is sample, you can create an item view with a textview and nonscrolling gridview

public class NonScrollGridView extends GridView {

    public NonScrollGridView (Context context) {
        super(context);
    }

    public NonScrollGridView (Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NonScrollGridView (Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // Do not use the highest two bits of Integer.MAX_VALUE because they are
        // reserved for the MeasureSpec mode
        int heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightSpec);
        getLayoutParams().height = getMeasuredHeight();


    }
}

Your RecyclerView item view

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/titleTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"/> 

    <com.example.NonScrollGridView 
        android:id="@+id/gridView"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:divider="@android:color/white"/>


</LinearLayout>