android的显式提交和隐式提交

1.MainActivity.java

package com.example.baihetest;

import org.w3c.dom.Text;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
	
	private EditText _editname;
	private EditText _editpwd;
	private RadioGroup _rGroup;
	private CheckBox checkBoxmoive;
	private CheckBox checkBoxfootball;
	private CheckBox checkBoxmountain;
	private CheckBox checkBoxfly;
	private String movie;
	private String football;
	private String mountain;
	private String fly;
	private String[] spjobs;
	private String job;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		_editname = (EditText) findViewById(R.id.username);
		_editpwd = (EditText) findViewById(R.id.pswd);
		_rGroup = (RadioGroup) findViewById(R.id.sex);
		//job
		Spinner spinner= (Spinner) findViewById(R.id.jobspinner);
		spjobs = getResources().getStringArray(R.array.job);
		/*ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, R.array.job);
		spinner.setAdapter(adapter);*/
		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

			

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				job = spjobs[position];
			
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub
				
			}
		});
		findViewById(R.id.showbtn).setOnClickListener(this);
		findViewById(R.id.hiddenbtn).setOnClickListener(this);
		findViewById(R.id.getall).setOnClickListener(this);
		findViewById(R.id.disall).setOnClickListener(this);
		checkBoxmoive = (CheckBox) findViewById(R.id.moive);
		checkBoxfootball = (CheckBox) findViewById(R.id.football);
		checkBoxmountain = (CheckBox) findViewById(R.id.mountain);
		checkBoxfly = (CheckBox) findViewById(R.id.fly);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.getall){
			checkBoxmoive.setChecked(true);
			checkBoxfootball.setChecked(true);
			checkBoxmountain.setChecked(true);
			checkBoxfly.setChecked(true);
		}
		if(v.getId()==R.id.disall){
			if(checkBoxmoive.isChecked()){
				checkBoxmoive.setChecked(false);
			}else {
				checkBoxmoive.setChecked(true);
			}
			if(checkBoxfootball.isChecked()){
				checkBoxfootball.setChecked(false);
			}else {
				checkBoxfootball.setChecked(true);
			}
			if(checkBoxmountain.isChecked()){
				checkBoxmountain.setChecked(false);
			}else {
				checkBoxmountain.setChecked(true);
			}
			if(checkBoxfly.isChecked()){
				checkBoxfly.setChecked(false);
			}else {
				checkBoxfly.setChecked(true);
			}
		}
		if(checkBoxmoive.isChecked()){
			movie = checkBoxmoive.getText().toString();
		}
		else{
			movie= null;
		}
		if(checkBoxfootball.isChecked()){
			football = checkBoxfootball.getText().toString();
		}else{
			football=null;
		}
		if(checkBoxmountain.isChecked()){
			mountain = checkBoxmountain.getText().toString();
		}else{
			mountain=null;
		}
		if(checkBoxfly.isChecked()){
			fly = checkBoxfly.getText().toString();	
		}else{
			fly=null;
		}
		String username=_editname.getText().toString();
		String pwd=_editpwd.getText().toString();
		String sex=null;
		// TODO Auto-generated method stub
		if(TextUtils.isEmpty(username)&&TextUtils.isEmpty(pwd)){
			Toast.makeText(MainActivity.this, "请输入usernameOrpwd", Toast.LENGTH_SHORT).show();
		}else{
			if(_rGroup.getCheckedRadioButtonId()==R.id.boy){
				sex="男";
			}else{
				sex="女";
			}
			if(v.getId()==R.id.showbtn){
			Intent intent= new Intent();
			ComponentName componentName=new ComponentName("com.example.baihetest", "com.example.baihetest.XianshiActivity");
			intent.setComponent(componentName);
			Bundle bundle = new Bundle();
			bundle.putString("uname", username);
			bundle.putString("upwd", pwd);
			bundle.putString("usex", sex);
			bundle.putString("moive", movie);
			bundle.putString("football", football);
			bundle.putString("mountain", mountain);
			bundle.putString("fly", fly);
			bundle.putString("job", job);
			intent.putExtras(bundle);
			startActivity(intent);
			}else if(v.getId()==R.id.hiddenbtn){
				Intent intent = new Intent();
				intent.setAction("ystj");
				Bundle bundle = new Bundle();
				bundle.putString("uname", username);
				bundle.putString("upwd", pwd);
				bundle.putString("usex", sex);
				bundle.putString("moive", movie);
				bundle.putString("football", football);
				bundle.putString("mountain", mountain);
				bundle.putString("fly", fly);
				bundle.putString("job", job);
				intent.putExtras(bundle);
				startActivity(intent);
			}
		}
	}


}
2.XianshiActivity.java

package com.example.baihetest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class XianshiActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_xianshi);
		Intent intent=getIntent();
		Bundle bundle=intent.getExtras();
		String username=bundle.getString("uname");
		String pwd=bundle.getString("upwd");
		String sex=bundle.getString("usex");
		String movie=bundle.getString("moive");
		String football=bundle.getString("football");
		String mountain=bundle.getString("mountain");
		String job=bundle.getString("job");
		String fly=bundle.getString("fly");
		TextView _tTextView= (TextView) findViewById(R.id.xianshi);
		_tTextView.setText("用户名:"+username+"|密码:"+pwd+"|性别:"+sex+"|爱好:"+movie+","+football+","+mountain+","+fly+"|职业:"+job);
	}

}

3.YinshiActivity.java

package com.example.baihetest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class YinshiActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_yinshi);
		Intent intent=getIntent();
		Bundle bundle=intent.getExtras();
		String username=bundle.getString("uname");
		String pwd=bundle.getString("upwd");
		String sex=bundle.getString("usex");
		String movie=bundle.getString("moive");
		String football=bundle.getString("football");
		String mountain=bundle.getString("mountain");
		String job=bundle.getString("job");
		String fly=bundle.getString("fly");
		TextView _tTextView= (TextView) findViewById(R.id.ystjtest);
		_tTextView.setText("用户名:"+username+"|密码:"+pwd+"|性别:"+sex+"|爱好:"+movie+","+football+","+mountain+","+fly+"|职业:"+job);
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值