1. Are you ready for the Galaxy S20? Here is everything we know so far!

create TextView on activityResult. No TextView displaying

Discussion in 'Android Development' started by btf271, Jan 4, 2014.

  1. btf271

    btf271 Lurker
    Thread Starter

    I'm trying to create a textView in the parent activity onActivityResult but the textView does not appear. There is an ImageView that takes up the whole parent activity. I can create a textView and place it, and it should go on top of the imageView?

    In the parent class:

    [HIGH]private void addClothes(int menuId) {

    Intent chooseClothesIntent = new Intent(this, ChooseClothesActivity.class);
    chooseClothesIntent.putExtra("menuId", menuId);
    startActivityForResult(chooseClothesIntent, 1);
    }[/HIGH]

    [HIGH]@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode) {
    case (1) : {
    if (resultCode == Activity.RESULT_OK) {
    String newText = data.getStringExtra("imagePath");
    TextView tv = new TextView(this);
    tv.setTextSize(10);
    tv.setTextColor(Color.RED);
    tv.setText(newText);
    LayoutParams lp = new LayoutParams(new ViewGroup.MarginLayoutParams(100,100));
    //tv.setLayoutParams(lp);
    //((MarginLayoutParams) lp).setMargins((int)texts.get(index).Sx, (int)texts.get(index).Sy, (int)texts.get(index).Lx, (int)texts.get(index).Ly);

    tv.setLayoutParams(lp);
    Log.d("tag", "I have set the text " + newText); //Logs successfully. newText is set correctly
    }
    break;
    }
    }
    }[/HIGH]

    then in my new activity:

    [HIGH]@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    try {
    ClothingItem ci = mListContents.get(position);
    String imagePath = ci.getImagePath();
    Log.d("path", imagePath); //this successfully logs the imagePath string
    Intent resultIntent;
    resultIntent = new Intent(this, DressingRoomActivity.class);
    resultIntent.putExtra("imagePath", imagePath);
    setResult(Activity.RESULT_OK, resultIntent);
    finish();
    } catch (Exception e) {
    Log.v(TAG, e.getMessage());
    }
    }[/HIGH]
     


  2. dev47

    dev47 Newbie

    I recommend having the TextView in your xml.
    Use android:visibility="invisible" to hide it, then in your onActivityResult, set/update the text and toggle the visibility (View.VISIBLE).
     
  3. btf271

    btf271 Lurker
    Thread Starter

    Thanks, I've got it working now. I had to create the imageView programmatically because I am adding images dynamically and it is not a set number of images. I didn't realise there is a final step: layout.addView(view);
     
Loading...
Similar Threads - create TextView activityResult
  1. bin_per
    Replies:
    0
    Views:
    301
  2. John Fueler
    Replies:
    1
    Views:
    169
  3. Samsung
    Replies:
    0
    Views:
    144
  4. DEMETRIOS J TSILLAS
    Replies:
    1
    Views:
    383
  5. bjourine stekarfield
    Replies:
    0
    Views:
    379
  6. Kayem59
    Replies:
    4
    Views:
    449
  7. sersaber
    Replies:
    1
    Views:
    320
  8. MoodyBlues
    Replies:
    8
    Views:
    2,243
  9. UmBottesWillen
    Replies:
    1
    Views:
    422

Share This Page

Loading...