android入门 上一步 下一步 保存数据 DEMO
[code="java"]DEMO 木有注视 吼吼 ~~~ [/code] [code="java"] package com.isoftstone.cry; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class StartActivityForResult_Next extends Activity { private Button btn ; private EditText username,password ; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.a_intent_01); //get Instance btn = (Button)findViewById(R.id.ai_button1); username = (EditText)findViewById(R.id.ai_username_ed01); password = (EditText)findViewById(R.id.ai_psd_editText2); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Bundle bundle = new Bundle(); bundle.putString("username",username.getText().toString()); bundle.putString("password",password.getText().toString()); Intent intent = new Intent(StartActivityForResult_Next.this, StartActivityForResult_Next2.class); intent.putExtras(bundle); startActivityForResult(intent, 0); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub Bundle bundle = data.getExtras(); String _username = bundle.getString("username"); String _password = bundle.getString("password"); username.setText(_username); password.setText(_password); } } [/code] [code="xml"] [/code] [code="java"] package com.isoftstone.cry; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class StartActivityForResult_Next2 extends Activity { private Button btn ; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.a_intent_02); btn = (Button)findViewById(R.id.ai_button02); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = getIntent(); //设置返回结果 StartActivityForResult_Next2.this.setResult(0,intent); //结束当前activity StartActivityForResult_Next2.this.finish(); } }); } } [/code] [code="xml"] [/code]