简体   繁体   中英

I didn't get anything in my recycler view when i select image from gallery to show in recyclerview android

I am just trying to pick image from gallery and show in recyclerview but when i go to the gallery and select image it show blank recyclerview here is my code

public void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == GALLERY)
        {
            if (data != null)
            {

                Bitmap photo = (Bitmap) data.getExtras().get("data");
                imageView.setImageBitmap(photo);
                recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                adapter = new ImageAdapter(imageArrayList);
                recyclerView.setAdapter(adapter);
                layoutManager = new LinearLayoutManager(this);
                recyclerView.setLayoutManager(layoutManager);
                //ImageAdapter adapter = new ImageAdapter (data, MainActivity.this);
                //recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
                recyclerView.smoothScrollToPosition(0);
                //Counter = false;
            }
        }
    }

i think you forgot add data in your imageArrayList

1. this first add data in Arraylist than set Adapter to your recyclerView

imageArrayList.add( add here your data);
adapter = new ImageAdapter(imageArrayList);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM