Android系统下如何在程序中对XML里面元素进行赋值
2008-05-07 09:23
507 查看
首先让我们来看MAIN.xml这个文件里面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:rientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
这里我在主窗体下,创建了一个TextView和一个EditText。
现在我的目的是对TextView进行赋值
我在TextView下增加一行:
android:id="@+id/body" //在id字串中+号跟在@号之后,显示了这个id如果不存在,则应当自动创建
当添加好以后,这时我们的R.java文件里面并没有生成这个
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040000;
}
在Android tools->>fix project properties点击以后,再看R.JAVA这个文件里面,就是增加一条:
public static final class id{
public staitc final int id =XXXXXXX;
}
返过头来,我们来看主文件:
我把代码贴出来!
public void onCreate(Bundle icicle) {
String in =resouce.Readresouce(inputway);
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.body);
tv.setText(“hello”);
首先是建立main主窗体
然后通过获取R.id.body来找到main.xml文件里面的TextView
<TextView
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
tv.setText(“hello”);
这里就是赋值了。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:rientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
这里我在主窗体下,创建了一个TextView和一个EditText。
现在我的目的是对TextView进行赋值
我在TextView下增加一行:
android:id="@+id/body" //在id字串中+号跟在@号之后,显示了这个id如果不存在,则应当自动创建
当添加好以后,这时我们的R.java文件里面并没有生成这个
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040000;
}
在Android tools->>fix project properties点击以后,再看R.JAVA这个文件里面,就是增加一条:
public static final class id{
public staitc final int id =XXXXXXX;
}
返过头来,我们来看主文件:
我把代码贴出来!
public void onCreate(Bundle icicle) {
String in =resouce.Readresouce(inputway);
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.body);
tv.setText(“hello”);
首先是建立main主窗体
然后通过获取R.id.body来找到main.xml文件里面的TextView
<TextView
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
tv.setText(“hello”);
这里就是赋值了。
相关文章推荐
- Android 调用系统的拍相程序进行录像
- 如何让自己的Android程序永不被系统kill
- 如何:用对称密钥对 XML 元素进行加密
- Mono For Android 如何控制程序在自动旋转功能开启下不进行横竖屏切换
- 如何在ubuntu系统里面用新加装的硬盘对系统进行扩容
- 数据结构--如何对一个线性表里面的元素赋值,并且显示插入一个数据后的情况
- Android程序的安全系统--以root权限进行操作
- Unity如何打包Android程序以及如何进行签名
- 如何用Google APIs和Google的应用系统进行集成(6)----如何把Google Calendar的JSON Schema转换成XML的Schema(XSD)?
- 如何让自己的Android程序永不被系统kill
- 5、xamarin.android 中如何对AndroidManifest.xml 进行配置和调整
- Android应用程序如何进行系统签名
- 如何处理android程序变为后台程序,系统回收资源,再次打开时,程序因为null指针等崩溃
- 如何让自己的Android程序永不被系统kill
- 如何将Android例子程序添加到Eclipse进行调试运行(转载)
- 如何在Unity中对程序进行 Android 真机断点调试
- Android调用系统自带的下载程序进行下载。
- 在Android系统的"图库"中点击某张图片进行分享,在自己的应用程序中如何获取那张图片的路径?
- 如何在Android系统中使用gzip进行数据传递
- Android如何实现对系统自带对话框标题栏进行修改