在android中链接两个activity
我正在编写一个简单的Android应用程序,您在一个框中写下您的名字,然后单击“确定”,一个新页面将显示您的名字...问题是,当您单击“确定”时什么也没有发生。
这里是主要活动
public class Click extends Activity implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String TypedText = (String)MyText.getText().toString();
Intent MyInt = new Intent(this, HelloWorld.class);
MyInt.putExtra("user", TypedText);
this.startActivity(MyInt);
Bundle Retrive = this.getIntent().getExtras();
Retrive.getString("user");
setContentView(R.id.Text);
TextView TextV = (TextView)findViewById(R.id.Text);
TextV.setText("user");
}
android.widget.EditText MyText;
public void OnCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.name_getter);
MyText = (EditText)this.findViewById(R.id.editText1);
this.findViewById(R.id.button1);
android.widget.Button RefBut = (Button)this.findViewById(R.id.button1);
RefBut.setOnClickListener(this);
}
,这里是清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.calpoly.android.lab1Sada"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Click"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="HelloWorld" ></activity>
</application>
</manifest>
启动 android 模拟器将启动第一个活动单击,但应用程序不会显示新视图...
I'm coding a simple android app where you write in a box your name then click ok and a new page will show your name... The problem is that when you click ok nothing happens.
Here the main activity
public class Click extends Activity implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String TypedText = (String)MyText.getText().toString();
Intent MyInt = new Intent(this, HelloWorld.class);
MyInt.putExtra("user", TypedText);
this.startActivity(MyInt);
Bundle Retrive = this.getIntent().getExtras();
Retrive.getString("user");
setContentView(R.id.Text);
TextView TextV = (TextView)findViewById(R.id.Text);
TextV.setText("user");
}
android.widget.EditText MyText;
public void OnCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.name_getter);
MyText = (EditText)this.findViewById(R.id.editText1);
this.findViewById(R.id.button1);
android.widget.Button RefBut = (Button)this.findViewById(R.id.button1);
RefBut.setOnClickListener(this);
}
And here the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.calpoly.android.lab1Sada"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Click"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="HelloWorld" ></activity>
</application>
</manifest>
Starting the android emulator will launch the first activity click but then the app doesn't show the new view...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道你在做什么,但你可以像这样从 Activity 发送/检索数据到另一个 Activity:
为此,你需要理解 意图。
来自第一个活动:
来自第二个活动:
仍然供您参考,这里是了解更多相同内容的文章: Android 意图
I dont know what you are doing but you can send/retrieve data from/to activity to another activity like this way:
For that you need to understand the concept of Intent.
From First activity:
From Second activity:
Still for your reference, here is the article to know more about the same: Android Intents
您必须传递来自活动 1 的文本并在活动 2 中将其作为捆绑包接收。
将 helloworld 程序作为您的第一个 Android 教程。
只需扩展 Activity 即可。您不需要提及超类的整个包。
You must pass the text from activity 1 and receive it as bundle in activity 2.
Go through the helloworld program as your first tutorial for android.
Just extending Activity will work. You do not need to mention the entire package of the superclass.