一个activity调用另外一个activity的有关问题
发布时间:2010-05-30 10:45:24 文章来源:www.iduyao.cn 采编人员:星星草
一个activity调用另外一个activity的问题?
我想做一个简单的练习,一个Activity02调用另外一个OtherActivity!调用成功,但是在被调用的OtherActivity中加了一个button,却始终显示不出来!调试的过程中能看到代码是调用了这个button的!
Activity02的代码:
public class Activity02 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button myButton=(Button)findViewById(R.id.myButton1);
myButton.setText("this is wbn button");
myButton.setOnClickListener(new MyButtonListener());
}
class MyButtonListener implements OnClickListener{
public void onClick(View view){
Intent intent=new Intent();
intent.setClass(Activity02.this, OtherActivity.class);
Activity02.this.startActivity(intent);
}
}
}
相应的layout目录下的main.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button android:id="@+id/myButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
OtherActivity代码:
public class OtherActivity extends Activity{
public void onCreate(Bundle bunle){
super.onCreate(bunle);
setContentView(R.layout.other);
TextView viewText=(TextView)findViewById(R.id.ViewText1);
viewText.setText("viewText test");
Button button2=(Button)findViewById(R.id.myButton2);
button2.setText("otherActivity Button");
}
}
相应的layout目录下的other.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/ViewText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/myButton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
AndroidManifest.xml文件内容为:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="myAndroid.activity02"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Activity02"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
Android版块严惩倒分行为,希望大家配合维持正当的技术交流 - 移动平台 / 非技术区
近期发现Android版块一些帐号在进行倒专家分操...
-
Java应用程序调用系统中任意一个so文件的方法 大家看看是否可行?
如果我想编写一个apk程序,而这个apk程序要调用系统中的非JNI的so...
-
关于ListView中CheckBox 用程序全选的问题
LisetView中view布局
XML code
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLay...
-
请教一个关于广播接收器优先级的问题,为什么我无论如何都不能超越QQ,360,GO等手机助手,管家?
android官方好像说最高1000,我试过...
-
Android 布局framelayout到底怎么用
简单demo就不要说了哈,知道framelayout的简单实例,感觉没有收获,看了源码,也没有什么感觉。我想...
-
如果调用系统剪裁功能
首先调用系统图库,获取图片,然后对该图片进行剪裁,大家帮忙看下我的代码哪里有问题
Java code
Uri uri = data...
-
求4.0的framework.jar包
如题。哪位朋友有编好的4.0的framework.jar,给个下载地址,或发我邮箱heixue888@qq.com
3Q~
------解决方案...
-
关于读取手机通讯录的问题
使用Android1.5的读取方法:
Cursor cur = context.getContentResolver().query(Contacts.Peop...
-
请教如何用android画图
我想利用android写一个画图程序,请问我应该重点看android的哪些部分,请大家给点建议,还有大家是否有相关的工...
-
分享HTC手机Android源代码下载地址
http://developer.htc.com/
------解决方案--------------------
不错,可惜只有kernel的~~...