skip to Main Content

I need to create a feed screen like facebook application where I will fetch data from api and each row has different size of images and text.
I know ScrollView is for both homogeneous and heterogeneous collection and listView is for only homogeneous collection but can I use listview for heterogeneous collections for feed. ?

2

Answers


  1. Chosen as BEST ANSWER

    Yes it is possible. React native handle is very efficiently. i have left no option except to implement and see if it works and yes it is working awesomely. Also this post help me a lots to go through Recycling Rows For High Performance React Native List Views Thanks


  2. You can try something like this:

    private List mList = new ArrayList();
    
    mList.add("String");
    mList.add('A');
    mList.add(true);
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ......
        ......
        ......
        if(mList.get(position) instanceof String){
    
        }else if(mList.get(position) instanceof Character){
    
        }else if(mList.get(position) instanceof Boolean){
    
        }
    }
    
    @Override
    public int getItemViewType(int position) {
        if(mList.get(position) instanceof String){
            return 0;
        }else if(mList.get(position) instanceof Character){
            return 1;
        }else if(mList.get(position) instanceof Boolean){
            return 2;
        }
        return 0;
    }
    

    Or normalize them into a common Class.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search