0

I am having an issue with updation of GridView items once its back from child activity. Once the griditem is clicked a child activity is opened which has two options as yes or no. I have to show an extra image in a gridview for that particular griditem if user selects yes, if not it should be the same old gridview. I am getting if user selected yes or no in "onActivityResult" present in GridView's activity. Now my issue is, I don't know how to show the extra image for that particular item in gridview. Any suggestions, please help me. Thanks a lot.

Lavanya
  • 3,903
  • 6
  • 31
  • 57

3 Answers3

2

Set up your ImageView in your xml design file, and then when you get your onActivityResult try executing the code to set a source to your ImageView, it should work with this:

ImageView image = (ImageView) findViewById(R.id.test_image);
image.setImageResource(R.drawable.test2);

I hope this helped you.

HappyDump
  • 443
  • 9
  • 18
  • In Adapter's getView() I am setting the custom xml file for each griditem. How will I set the image in onActivityResult() ? There should be some change to do in Adapter, right? – Lavanya Oct 08 '13 at 09:24
  • Maybe try to set the `ImageView.setVisibility()` to `View.GONE` so it won't have any weight in your layout untill you want to display it. – HappyDump Oct 08 '13 at 09:29
1

Just set your image to an ImageView and then add your ImageView to the parent layout of your custom grid item layout with params as your requirement.

Harish Godara
  • 2,388
  • 1
  • 14
  • 28
1

Just Pass the Image from your child Activity like,

YesButton.setOnclickListener(new onClickListener()
{
  public void onClick(View v)
  {
    Intent csIntent=new Intent(); 
    csIntent.put("image","name");
    setResult(RESULT_OK, csIntent);
    finish();
  }
});

and main Activity,

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

    super.onActivityResult(requestCode, resultCode, data);
    `enter code here`get that image and once again load and refresh the GridAdapter here.
}
Lavanya
  • 3,903
  • 6
  • 31
  • 57
rkv
  • 131
  • 6
  • loading data again in onActivityResult has worked for me. But when I again go into child activity by clicking on other item and I choose yes for that, then only for this item I am able to show the extra image. The before answered question is not showing the image. What has to be done. Please help me – Lavanya Oct 09 '13 at 06:44
  • need to save the position and image in every updation in your Gridview.then only when you come back to your parent activity while you can display the same image in specific position – rkv Oct 09 '13 at 07:05