Reputation: 13
I am using a custom array adapter and displaying an image and some text within each row (JSON from a movie database API). When I change the orientation of the device, the list is loaded again and everything is displayed correctly, even though I have not specified a landscape orientation anywhere in the code. So far, great!
My problem is that in the landscape orientation I would like to only change the image that I am loading (using Picasso since it is an image URL). I want everything else to remain as is.
How can I achieve the same? Does Picasso itself have a function which could take care of such an issue?
Let me know if some code is needed. Thanks!
Upvotes: 0
Views: 424
Reputation: 60933
You should detect when your device change orientation
Then you should update the list datasource base on orientation and notifyDataSetChanged
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// change all image path in listdata to landscape path
// for example
// for (Item item : listData) {
// item.setDisplayImagePath(landscapePath);
// }
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
// change all image path in listdata to portrait path
}
youListViewAdapter.notifyDataSetChanged();
}
Hope this help
Upvotes: 1
Reputation: 144
You can try this piece of code:
Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
if (rotation != 0) {
Picasso.with(getApplicationContext()).load(your_url).into(your_imageview);
}
It detects if there's a screen rotation, the display.getRotation returns an int (that equals 0 if there isn't any rotation), from there you can use Picasso to change your imageview.
Cheers,
Upvotes: 0