1. Download our Official Android App: Forums for Android!

Apps create TextView on activityResult. No TextView displaying

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

  1. btf271

    btf271 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jan 4, 2014

    Jan 4, 2014
    2
    0
    5
    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]
     

    Advertisement

  2. dev47

    dev47 Newbie
    Rank:
    None
    Points:
    16
    Posts:
    17
    Joined:
    Apr 13, 2010

    Apr 13, 2010
    17
    5
    16
    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
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jan 4, 2014

    Jan 4, 2014
    2
    0
    5
    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);
     

Share This Page

Loading...