【发布时间】:2014-02-05 14:18:49
【问题描述】:
我有一个显示布局,其中一个是 imageView,另一个是 TextView。我正在使用这个布局显示很多东西,但是有一个问题。问题是假设我运行一个活动使用这个布局这个活动填充它并杀死自己。稍后如果我调用另一个活动使用该布局,它会更改图像但文本仍然相同。我不想发布所有代码但如果你们需要我可以发布它。
setContentView(R.layout.info_display_tablet);
iv = (ImageView) findViewById(R.id.imageView1);
tx = (TextView) findViewById(R.id.textView1);
try {
result = MethodInfoGetter.methodRequest("CTVIslemleriGetir", "", "");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tx.setText("");
iv.setImageResource(R.drawable.cevre_temizlik);
tx.setText(result.get(0).get(1).toString());
这是我的第一个电话让我们假设第二个电话的代码是
public class BalikesirTarih extends Activity
{
ArrayList<ArrayList> result = new ArrayList<ArrayList>();
ImageView iv;
TextView tx;
Bitmap bmp = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.info_display_tablet);
iv = (ImageView) findViewById(R.id.imageView1);
tx = (TextView) findViewById(R.id.textView1);
try {
result = MethodInfoGetter.methodRequest("BalikesirTarihiGetir", "", "");
Log.i("Balikesir tarihi log denemesi",result.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new asTask().execute();
}
private class asTask extends AsyncTask<Void , Void ,Void> {
@Override
protected Void doInBackground(Void... params) {
URL url = null;
try {
url = new URL("http://balikesir.bel.tr/Balikesir_Tarihi/Resim_b_1.jpg");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
iv.setImageBitmap(bmp);
tx.setText("");
tx.setText(result.get(0).get(1).toString());
}
}
@Override
protected void onPause() {
super.onPause();
finish();
}
}
【问题讨论】:
-
您不必发布所有代码,但如果没有相关部分,我们将无法为您提供帮助。
-
该文本将是您每次加载时
layout.xml文件中的默认文本,除非您保存该值并在为layout充气时专门设置它。我认为您需要提供 一些 代码和/或更好的解释,因为这很令人困惑。 -
这是我在程序中调用的代码。
-
您是否检查了您的
try/catch以查看您是否遇到异常或result是否正在初始化为预期值? -
我看起来它返回不同的数据,但我无法更改文本。
标签: android android-layout textview android-activity