MainActivity.javajava
public class MainActivity extends Activity {
private EditText editText = null;
private Button button = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText)findViewById(R.id.editText);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new ButtonOnClickEvent());
}
class ButtonOnClickEvent implements OnClickListener{
@Override
public void onClick(View v) {
//獲取edittext文件內容
String et1Str = editText.getText().toString();
Intent intent = new Intent();
intent.putExtra("editText", et1Str);
intent.setClass(MainActivity.this,otherActivity.class);
//實現跳轉
MainActivity.this.startActivity(intent);
}
}//class結束
}android
otherActivity.javaapp
public class otherActivity extends Activity{
private TextView myTestView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
Intent intent = getIntent();
String value = intent.getStringExtra("editText");
myTestView = (TextView)findViewById(R.id.myTestView);
myTestView.setText(value);
}
}ide
main.xml文件this
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
>
<!-- android:gravity="right"表示Button組件向右對齊 -->
<Button
android:id="@+id/button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="肯定"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="取消"
/>
</LinearLayout>xml
other.xml文件get
<TextView
android:id="@+id/myTestView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>string
<!-- otherActivity.java的配置文件 -->
<activity
android:name=".otherActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
it