package com.example.bundle;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract.Data;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class MainActivity extends
Activity {


EditText mEditText;
Button mButton;



@Override
public void onCreate(
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEditText = (EditText) findViewById(R.id.editText1);
mButton = (Button) findViewById(R.id.button1);

mButton.setOnClickListener(new OnClickListener() {


public void onClick(View v) {
// TODO Auto-generated method stub


CharSequence intputData = mEditText
.getText()
.toString();


Bundle bundle=new Bundle();
bundle.putCharSequence("datee", intputData);
Intent intent=new Intent(MainActivity.this,Data1.class);
intent.putExtras(bundle);
startActivity(intent);
}

});



--------------------------Data1.java
package com.example.bundle;


import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;


public class Data1 extends Activity {
EditText editText2;


@Override
protected void onCreate(
Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mian1);
editText2 = (EditText) findViewById(R.id.editText2);
Bundle shareBundle = getIntent()
.getExtras();
if (shareBundle != null) {


CharSequence charSequence = shareBundle
.getCharSequence("datee");


editText2
.setText(charSequence);
}


}
}

}


@Override
public boolean onCreateOptionsMenu(
Menu menu) {
getMenuInflater().inflate(
R.menu.activity_main,
menu);
return true;
}
}


From:CSDN

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()