【问题标题】:Android UI XML LayoutAndroid UI XML 布局
【发布时间】:2010-10-21 07:45:38
【问题描述】:

我已经在 main.xml 中创建了 textview 布局,我想在模拟器上看到效果,但我没有得到我的更改,当我在模拟器中运行我的应用程序时它显示旧结果.....

例如:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/textview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:text="@string/hello"/>

字符串:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello, Android! I am a string resource!</string>
    <string name="app_name">Hello, Android</string>
</resources>

如果有人知道,请帮忙........

【问题讨论】:

  • 什么样的效果?你试过什么?给我们一些代码和更多解释,因为我真的不明白你想做什么......
  • 大家好,我是 android 新手,我已经简单地创建了一个 HelloAndroid 应用程序,我想尝试使用 xml 布局。我已经通过开发人员指南完成了它,但是在运行应用程序后它没有显示我写入 string.xml 的内容

标签: android android-emulator


【解决方案1】:

您可能需要使用 setContentView() 设置 Activity 的 contentView 以指向新布局

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
   }
}

在“将 UI 升级为 XML 布局”下查看更多信息 http://developer.android.com/resources/tutorials/hello-world.html

【讨论】:

  • 大家好,我是 android 新手,我已经简单地创建了一个 HelloAndroid 应用程序,我想尝试使用 xml 布局。我已经通过开发人员指南完成了它,但是在运行应用程序后它没有显示我写入 string.xml 的内容
【解决方案2】:

如果您想动态更改您需要的文本视图中的文本:

  • 为您的活动设置内容视图:

    setContentView(R.layout.main);
    
  • 获取对 TextView 对象的引用:

    TextView tv= (TextView)findViewById(R.id.textview);
    
  • 赋予新价值:

    tv.setText(R.string.app_name);
    

【讨论】:

  • 你能告诉我“v”的意思吗?在这一行 TextView tv= (TextView)v.findViewById(R.id.textview); ?
  • 哎呀,错过了。打算只写 findViewById()。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多