【发布时间】:2014-11-06 16:49:39
【问题描述】:
我正在尝试设置另一个类的 textview 文本 textview 在主要活动中,我需要从另一个不是活动的类中设置它
过去我使用过以下
public class DemoActivity extends Activity {
public static TextView textViewObj1;
public static TextView textViewObj2;
public static TextView textViewObj3;
public static TextView textViewObj4;
public static TextView textViewObj5;
public void onCreate(final Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textViewObj1 = (TextView) findViewById(R.id.Sitename);
textViewObj2 = (TextView) findViewById(R.id.Building);
textViewObj3 = (TextView) findViewById(R.id.Floor);
textViewObj4 = (TextView) findViewById(R.id.Roomno);
textViewObj5 = (TextView) findViewById(R.id.Drawref);
然后我通过使用将它设置在另一个类中
DemoActivity.textViewObj1.setText(c.getString(1));
DemoActivity.textViewObj2.setText(c.getString(2));
DemoActivity.textViewObj3.setText(c.getString(3));
DemoActivity.textViewObj4.setText(c.getString(4));
DemoActivity.textViewObj5.setText(c.getString(5));
我遇到的问题是我试图将其设置为使用片段的应用程序,因此主要活动而不是像这样开始
public class DemoActivity extends Activity {
这样开始
public class DemoActivity extends FragmentActivity {
由于某种原因,当我尝试使用其他类设置文本视图时
DemoActivity.textViewObj5.setText(c.getString(5));
它给出了错误:DemoActivity 无法解析
有什么想法吗?
我们一如既往地感谢您的帮助
标记
【问题讨论】:
-
您不能将视图称为静态视图,因为您在
DemoActivity中的视图仅在创建DemoActivity的实例时创建。 -
我不明白你的意思。当您使用 Extends Activity 时,它可以正常工作
标签: android class android-fragments textview