我想更改TextView
inonActivityResult
方法的文本。它似乎设置正确,但我在view
.
那TextView
是在第三Fragment
个ViewPager
。
所以这是我的代码:
public class TabsFacturasActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pager);
//...
mAdapter = new MyAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
//...
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
adjunto = true;
// Get the Uri of the selected file
Uri uri = data.getData();
// Get the path
String path = "";
try {
path = MyUtility.getPath(this, uri);
} catch (URISyntaxException e) {
myApplication.throwException(this);
e.printStackTrace();
}
String imgName = path.split("/")[path.split("/").length-1];
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.activity_lectura, null, false);
textViewImg = (TextView) view.findViewById(R.id.textViewUrlImgLectura);
System.out.println("text view before: "+textViewImg.getText()); //It returns correct value "..."
textViewImg.setText(imgName);
textViewImg.invalidate(); //It does nothing
System.out.println("text view after: "+textViewImg.getText()); //It returns correct value with image path
filePath = path;
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
private static class MyAdapter extends FragmentPagerAdapter {
private String[] titles = { "VER FACTURAS", "VER CONSUMO", "INTRODUCIR LECTURA" };
public MyAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0: // Fragment # 0
return new FacturasActivity();
case 1: // Fragment # 1
return new ConsumoActivity();
case 2:// Fragment # 2
return new LecturaActivity(); //TextView is here
}
return null;
}
@Override
public int getCount() {
return titles.length;
}
}
}
如您所见,我尝试过使用invalidate
,但它什么也没做。我该如何解决这个问题?