0
Guys I have a grid view that displays images of a server, when clika in the image I have to reload the image a few more details, I wanted instead of having to download the image again, That is, I wanted to move the image from the already loaded imageview to another imageview. A Gridview
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//String pid = ((TextView) view.findViewById(R.id.pid)).getText().toString();
String pid = productsList.get(position).getPid();
ImageView iv = (ImageView) view.findViewById(R.id.flag);
Bitmap bitmap = ((BitmapDrawable)iv.getDrawable()).getBitmap();
DetailFragment f = new DetailFragment();
Bundle args = new Bundle();
args.putParcelable("SEU_BITMAP", bitmap);
f.setArguments(args);
boolean singlepane = MainActivity.getPane();
if(singlepane== true){
/*
* The second fragment not yet loaded.
* Load DetailFragment by FragmentTransaction, and pass
* data from current fragment to second fragment via bundle.
*/
DetailFragment detailFragment = new DetailFragment();
Fragment myListFragment = getFragmentManager().findFragmentByTag("ListFragment");
Bundle bundle = new Bundle();
bundle.putString("TAG_PID",pid);
detailFragment.setArguments(bundle);
FragmentTransaction fragmentTransaction =
getActivity().getFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(
R.anim.fadein, R.anim.fadeout, R.anim.fadein, R.anim.fadeout);
//This could use some improvement, but it works, hide current fragment, show new one
fragmentTransaction.hide(myListFragment);
fragmentTransaction.add(R.id.phone_container, detailFragment);
//fragmentTransaction.show(myDetailFragment);
/*
* Add this transaction to the back stack.
* This means that the transaction will be remembered after it is
* committed, and will reverse its operation when later popped off
* the stack.
*/
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
The Second Party
getActivity().runOnUiThread(new Runnable() {
public void run() {
//creating the variables
String description;
String name;
String tags;
String downloads;
String created;
try {
//filling the variables with json content
url = (product.getString(TAG_URL));
//description = (product.getString(TAG_DESCRIPTION));
name = (product.getString(TAG_NAME));
tags = (product.getString(TAG_TAGS));
downloads = (product.getString(TAG_DOWNLOADS));
created = (product.getString(TAG_CREATED));
// Getting the tags in a gridview
stringArray = tags.split(",");
for (int i = 0; i < stringArray.length; i++)
stringArray[i] = stringArray[i].trim();
mylistview = (ExpandableHeightGridView) getActivity().findViewById(R.id.listViewTags);
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(getActivity(),
R.layout.tag_gridview_item, R.id.tagbutton,
stringArray);
mylistview.setAdapter(listAdapter);
Bitmap bitmap = getArguments().getParcelable("SEU_BITMAP");
imageView.setImageBitmap(bitmap);
Turns out The putExtra method(String, Bitmap) is Undefined for the type Bundle
– Alisson Hirle
My mistake, the correct method is
putParcelable
, corrected in response.– Wakim
Ta passing a null image, shows nothing.
– Alisson Hirle
Could you include in the question how was the code?
– Wakim
I put a part.
– Alisson Hirle
@Alissonhirle, from what I saw of the code you instance the
DetailFragment
twice, once with the variablef
, that has Bitmap and another with the variabledetailFragment
who doesn’t have theBitmap
and then ends up just using thedetailFragment
to do thereplace
.– Wakim
It worked, thank you.
– Alisson Hirle