我有以下布局的 main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textview01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
我正在尝试使用以下代码检索文本,即@string/hello
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv= (TextView) findViewById(R.id.textview01);
String input= tv.getText().toString();
Log.d("Info",input);
但是我看不到输出。应用程序在 String input = tv.getText(
最佳答案
你需要打电话
setContentView(R.layout.main);
在调用 findViewById
之前
关于android - 如何从 main.xml 中检索 TextView 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9156447/