-1

I am trying to show data from my DataObject on my Activity. Everything works fine and do not crash anywhere but my views are not updated with the information. I'm begginner on android, I know this... Please Can anyone help me? Thanks

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

        LayoutInflater inflater = LayoutInflater.from(DetailActivity.this);
        vp = (RelativeLayout)inflater.inflate(R.layout.activity_detail, null);

        String object_id = getIntent().getStringExtra("getIn"); // Get object_id from Intent

        DataQuery query = DataQuery.get("Id");
        query.getInBackground(object_id, new GetCallback<DataObject>() {
            @Override
            public void done(DataObject object, DataException e) {
                if (e == null) {
                        TextView price = (TextView)vp.findViewById(R.id.priceD);
                        price.setText((String) object.get("price"));


                        TextView productD = (TextView)vp.findViewById(R.id.productD);
                        productD.setText((String) object.get("product"));

                        ImageView  thumbnail=  (ImageView)vp.findViewById(R.id.thumbnail2);
                        thumbnail.setImageBitmap((Bitmap) object.get("image"));

                        TextView descriptionD = (TextView)vp.findViewById(R.id.description );
                        descriptionD.setText((String) object.get("description"));


                  //  }

                } else {
                    // Error

                }
            }
        });
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Miki
  • 103
  • 1
  • 1
  • 13
  • are you sure, `e` is not null and done method is called? Try using logcat to get the result. – Rahul Nov 01 '17 at 11:18
  • I'm sure, because I debug the application, and I see the data of every variable, but I see, in the method set text, but the activity don't refresh... – Miki Nov 01 '17 at 11:27

2 Answers2

0

You can simply use:

finish();
startActivity(getIntent());

to refresh an Activity from within itself.

Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
0

When you have setContent to Activity why are you inflating same XML again? Remove these lines:

 LayoutInflater inflater = LayoutInflater.from(DetailActivity.this);
    vp = (RelativeLayout)inflater.inflate(R.layout.activity_detail, null);

Also remove its reference when finding view. Just use:

TextView price = (TextView)findViewById(R.id.priceD);

Currently, your changes in background method changes view inside inflated view and not on Activity's view so changes are not visible. Remove above code and it will work fine.

nitinkumarp
  • 2,120
  • 1
  • 21
  • 30