package com.example.test1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
////////////////////
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.content.Intent;
////////////////////
public class MainActivity extends ActionBarActivity {
////////////////////
private EditText myText;
private EditText text_return1;
private EditText text_return2;
private Button myButton01;
private Button myButton02;
private Button myButton06;
private Button myButton08;
private Button myButton082;
private Button myButton09;
////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//////////0/////////
myText = (EditText)findViewById(R.id.editText1);
text_return1 = (EditText)findViewById(R.id.editText01);
text_return2 = (EditText)findViewById(R.id.editText02);
myButton01 = (Button)findViewById(R.id.Button01);
myButton02 = (Button)findViewById(R.id.Button02);
myButton06 = (Button)findViewById(R.id.Button06);
myButton08 = (Button)findViewById(R.id.Button08);
myButton082 = (Button)findViewById(R.id.Button082);
myButton09 = (Button)findViewById(R.id.Button09);
////////////////////
//////////1/////////
myButton01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
myText.setText("弄明白监听!");
}
});
////////////////////
/////////2//////////
myButton02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
////打开一个伪窗口------- 测试通过
Toast.makeText(getApplicationContext(), "提示:点击窗口外部关闭窗口!",
Toast.LENGTH_SHORT).show();
}
});
////////////////////
/////////6//////////
myButton06.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
////显示文本------- 测试通过
//myText.setText("弄明白监听2!");
////打开一个伪窗口------- 测试通过
//Toast.makeText(getApplicationContext(), "提示:点击窗口外部关闭窗口!",
//Toast.LENGTH_SHORT).show();
////intent负责程序跳转和传递数据
//只打开新窗体,不回传数据
Intent intent = new Intent(MainActivity.this, F1_TC.class);
startActivity(intent);
}
});
////////////////////
/////////8//////////
myButton08.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
////intent负责程序跳转和传递数据
//打开新窗体,回传数据
Intent intent = new Intent(MainActivity.this,Popu_TC.class);
Bundle bundle = new Bundle(); //通过Bundle实现数据的传递:
bundle.putString("key0", "value1"); // key0为名,value1为值
bundle.putString("key1", myText.getText().toString());
bundle.putString("key2", myText.getText().toString());
bundle.putString("key3", myText.getText().toString());
bundle.putInt("keyInt1", 100); //整数类型
intent.putExtras(bundle); // 传数据
//startActivity(intent); // ------- 测试通过 //不需要子窗口回传数据
//startActivityForResult(intent, requestCode); //requestCode是子窗口的id标志,而且必须大于1,否则回调函数onActivityResult不响应!
startActivityForResult(intent, 1); //如果需要子窗口回传数据:
}
});
////////////////////
/////////82//////////
myButton082.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
////intent负责程序跳转和传递数据
//打开新窗体,回传数据
Intent intent = new Intent(MainActivity.this,F2_TC.class);
Bundle bundle = new Bundle(); //通过Bundle实现数据的传递:
bundle.putString("key0", "value1"); // key0为名,value1为值
bundle.putString("key1", myText.getText().toString());
bundle.putString("key2", myText.getText().toString());
bundle.putString("key3", myText.getText().toString());
bundle.putInt("keyInt1", 100); //整数类型
intent.putExtras(bundle); // 传数据
//startActivity(intent); // ------- 测试通过 //不需要子窗口回传数据
//startActivityForResult(intent, requestCode); //requestCode是子窗口的id标志,而且必须大于1,否则回调函数onActivityResult不响应!
startActivityForResult(intent, 2); //如果需要子窗口回传数据:
}
});
////////////////////
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
////////////////////
//实现回调函数onActivityResult
//public void enterSecond(View view) {
//Intent intent=new Intent(this,com.example.test1.Popu_TC.class);
//startActivityForResult(intent, REQUEST_CODE);
//}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//String result2=data.getStringExtra("popu_key1");
//text_return1.setText(result2);
String str_result="";
switch (requestCode) {
case 1:
str_result=data.getStringExtra("re_key1");
text_return1.setText(str_result);
break;
case 2:
str_result=data.getStringExtra("re_key2");
text_return2.setText(str_result);
break;
}
}
////////////////////
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package com.example.test1;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
////////////////////
import android.view.View;
////////////////////
public class Popu_TC extends ActionBarActivity {
////////////////////
private EditText Text_Popu;
private Button myButton;
private EditText Text_return;
////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popu__tc);
////////1///////////
Text_Popu = (EditText)findViewById(R.id.editText_Popu);
myButton = (Button)findViewById(R.id.btn_popu);
Text_return = (EditText)findViewById(R.id.editText_last);
////////////////////
////////2///////////
Bundle bunde = this.getIntent().getExtras();
//String strs = bunde.getString("key3").toString();
Text_Popu.setText(bunde.getString("key1").toString());
////////////////////
////////3///////////
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
////intent负责程序跳转和传递数据
Intent intent = new Intent();
intent.putExtra("re_key1", Text_return.getText().toString()); // key1为名,value1为值
//intent.putExtras(bundle); // 传数据
//setResult(RESULT_OK, intent);
//finish();
//SubActivity.this.setResult(RESULT_OK, intent);
//SubActivity.this.finish();
//setResult(RESULT_OK, intent); //设置返回结果
//finish(); //关闭子窗口,否则数据无法返回
setResult(RESULT_OK, intent);
finish();
}
});
////////////////////
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.popu__tc, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package com.example.test1;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
////////////////////
import android.view.View;
////////////////////
public class F2_TC extends ActionBarActivity {
////////////////////
private EditText Text_in2;
private Button myButton;
private EditText Text_return2;
////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_f2__tc);
////////1///////////
Text_in2 = (EditText)findViewById(R.id.editText_in);
myButton = (Button)findViewById(R.id.btn_popu);
Text_return2 = (EditText)findViewById(R.id.editText_out);
////////////////////
////////2///////////
Bundle bunde = this.getIntent().getExtras();
//String strs = bunde.getString("key3").toString();
Text_in2.setText(bunde.getString("key2").toString());
////////////////////
////////3///////////
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
////intent负责程序跳转和传递数据
Intent intent = new Intent();
intent.putExtra("re_key2", Text_return2.getText().toString()); // key1为名,value1为值
//intent.putExtras(bundle); // 传数据
//setResult(RESULT_OK, intent);
//finish();
//SubActivity.this.setResult(RESULT_OK, intent);
//SubActivity.this.finish();
//setResult(RESULT_OK, intent); //设置返回结果
//finish(); //关闭子窗口,否则数据无法返回
setResult(RESULT_OK, intent);
finish();
}
});
////////////////////
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.f2__tc, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////