• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps create TextView on activityResult. No TextView displaying

btf271

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

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones