完成大写转换并返回结果
两个页面XML文件如下:
1.activity_main.xml:
2.slave.xml
两个代码如下
1.MainActivity.java
1.MainActivity.java
package com.leansmall.mydeom;
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;
import android.widget.TextView;
public class MainActivity extends Activity {
private EditText eText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eText=(EditText)this.findViewById(R.id.editText1);
tText=(TextView)this.findViewById(R.id.textView1);
button=(Button)this.findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Bundle bundle=new Bundle();
bundle.putString("value",eText.getText().toString());
Intent intent=new Intent(MainActivity.this,slave.class);
intent.putExtras(bundle);
startActivityForResult(intent, 10);
}
});
}
protected void onActivityResult(int requestCode,int resultCode,Intent Data) {
}
}
2.slave.java
package com.leansmall.mydeom;
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;
public class slave extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slave);
button=(Button)this.findViewById(R.id.button1);
Intent intent=this.getIntent();
Bundle bundle=intent.getExtras();
value=bundle.getString("value");
value=value.toUpperCase();
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
注意:两个acitvity都需要在AndroidManifest.xml的application中注册才可以使用