这个问题就是,我已经给myTextView建立了一个ID,但是在使用findViewById查找时遇到问题,将函数findViewById的返回值强行转化为TextView类,代码为TextView myTextView=(TextView)findViewById(R.id.myTextView);
这行代码的两个TextView都显示TextView不能被解析成一个变量,我的SRC源文件如下
package hi.hello;import android.app.Activity;
import android.os.Bundle;public class HiActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView myTextView=(TextView)findViewById(R.id.myTextView);//从这里出现问题
myTextView.setText("我的第一个TextView");
}
}
Main.xml如下
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myTextView"/></LinearLayout>
R.JAVA如下
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/package hi.hello;public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int myTextView=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
不知问题出在哪里,我初学
这行代码的两个TextView都显示TextView不能被解析成一个变量,我的SRC源文件如下
package hi.hello;import android.app.Activity;
import android.os.Bundle;public class HiActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView myTextView=(TextView)findViewById(R.id.myTextView);//从这里出现问题
myTextView.setText("我的第一个TextView");
}
}
Main.xml如下
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myTextView"/></LinearLayout>
R.JAVA如下
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/package hi.hello;public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int myTextView=0x7f050000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
不知问题出在哪里,我初学
解决方案 »
- android中的ViewPager组件设置adapter不生效的疑问
- android TextView setMovementMethod 滑动 背景
- List集合排序问题
- android通讯录编写思路
- 如何修改/data/app目录下程序文件权限
- android 编译问题 (找不到文件)
- Android动态显示时间问题(请高手帮忙看一下)
- Androis Log 输出到什么目录什么文件中?
- 关于c程序移植到Android平台上的问题
- 这个程序在android studio中运行不了;
- 开发个类似微博或论坛的应用,怎么开发啊
- Fedora 16 编译 android (2.3),求详细资料,谢谢!
import android.widget.TextView;