MainActivity.java的代码
package com.example.activity;import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;public class MainActivity extends Activity {
private EditText et;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button transdata=(Button)findViewById(R.id.ok);
et=(EditText)findViewById(R.id.message);
transdata.setOnClickListener(new OnClickListener(){
public void onClick(View v){
String transMessage=et.getText().toString();
Bundle bundle=new Bundle();
bundle.putString("data",transMessage);
Intent intent=new Intent();
intent.setClass(MainActivity.this, ResultActivity.class);
intent.putExtras(bundle);
startActivity(intent);
}
});
}
}
ResultActivity.java的代码package com.example.activity;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;public class ResultActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
TextView tv=(TextView)findViewById(R.id.getdata);
Intent intent=getIntent();
Bundle bd=intent.getExtras();
String getdata=bd.getString("data");
tv.setText(getdata);
}}activity_main.xml的布局<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/kkk" /> <Button android:id="@+id/ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/trans"/>
</LinearLayout>
result.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:id="@+id/getdata"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>AndroidManifest.xml的部分配置
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ResultActivity"></activity>
</application>
运行总提示:The application activity(process com.example.activity) has stopped unexpectedly.please try again.不清楚哪里出了问题,帮忙看下,谢谢谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货