I have one Activity Class where Image are displayed in Grid view of 2 column. I use the following code to display the images
public class BooksPage extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
String image[] = { "http://ecx.images-amazon.com/images/I/51cGqWqQPJL._SX258_BO1,204,203,200_.jpg"
,"http://ecx.images-amazon.com/images/I/91WAYiiPwML.jpg"
,"http://ecx.images-amazon.com/images/I/51CEndEnxCL._SX383_BO1,204,203,200_.jpg"
,"https://s3-ap-southeast-1.amazonaws.com/prod-textnook/bookimages/9788185749815.jpg"
,"http://ecx.images-amazon.com/images/I/51DyYdNU5mL.jpg"
,"http://ecx.images-amazon.com/images/I/61yhyD3HvkL.jpg"
,"http://www.skkatariaandsons.com/Best%20Sellers/978-81-85749-73-0.jpg"
,"http://ecx.images-amazon.com/images/I/81FGjPtdvnL.jpg"};
String stream[]= {"MSC Physics","MSC Chemistry","MSC Biology",
"MSC Geology","BBS|BBA","CA","Bachelor","+2 Science"};
TextView navName,navEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_books_page);
RecyclerView favPlaces = (RecyclerView) findViewById(R.id.favPlaces);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
favPlaces.setLayoutManager(layoutManager);
favPlaces.setHasFixedSize(true);
ArrayList<BookDetails> placeList = getPlaces();
StaggeredAdapter staggeredAdapter = new StaggeredAdapter(this,placeList);
favPlaces.setAdapter(staggeredAdapter);
navName.setText(PreferenceManager.getDefaultSharedPreferences(this).getString("name","null"));
navEmail.setText(PreferenceManager.getDefaultSharedPreferences(this).getString("email","null"));
}
private ArrayList<BookDetails> getPlaces() {
ArrayList<BookDetails> details = new ArrayList<>();
for (int index=0; index<image.length;index++){
details.add(new BookDetails(image[index],stream[index]));
}
return details;
}
}
}
But instead of using url, I would like to use the image from the drawable folder.
How can I do that..Please help.
Thanks in advance.