Android用户注册的Activity

1、UserLogin的Activity

package cn.dccssq;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class UserLogin extends Activity {

	private static final String[] citites = { "Beijing", "Tokyo", "ATown",
			"BTower" };
	private EditText name, age, pass;
	private Button regBtn;
	private RadioGroup sextRdoGrp;
	private CheckBox baseball, basketball, football, tennis;
	private Spinner citySpinner;

	private boolean flag = true;
	private List favorites;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		favorites = new ArrayList();

		name = (EditText) findViewById(R.id.nameValue);
		age = (EditText) findViewById(R.id.ageValue);
		pass = (EditText) findViewById(R.id.passValue);
		regBtn = (Button) findViewById(R.id.registerButton);
		citySpinner = (Spinner) findViewById(R.id.cityItems);
		sextRdoGrp = (RadioGroup) findViewById(R.id.sexMenu);

		baseball = (CheckBox) findViewById(R.id.checkboxbaseball);
		favorites.add(baseball);

		basketball = (CheckBox) findViewById(R.id.checkboxbasketball);
		favorites.add(basketball);

		football = (CheckBox) findViewById(R.id.checkboxfootball);
		favorites.add(football);

		tennis = (CheckBox) findViewById(R.id.checkboxtennis);
		favorites.add(tennis);

		ArrayAdapter adapter = new ArrayAdapter(UserLogin.this,
				android.R.layout.simple_spinner_item, citites);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		citySpinner.setAdapter(adapter);

		regBtn.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				flag = addUser();
				if (flag) {
					new AlertDialog.Builder(UserLogin.this)
							.setTitle("Please Confirm the Information:")
							.setMessage(
									"Your Information:" + "/n" + "Name:"
											+ name.getText().toString() + "/n"
											+ "Age:" + age.getText().toString()
											+ "/n" + "Sex:" + getSex() + "/n"
											+ "Favorite:" + getFavorite()
											+ "/n" + "City:" + getCity() + "/n")
							.setCancelable(false)
							.setPositiveButton("Confirm",
									new DialogInterface.OnClickListener() {

										public void onClick(
												DialogInterface arg0, int arg1) {
											// TODO Auto-generated method stub
											ProgressDialog.show(UserLogin.this,
													"Signing",
													"Please wait.....")
													.setCancelable(true);
										}
									})
							.setNegativeButton("Edit",
									new DialogInterface.OnClickListener() {

										public void onClick(
												DialogInterface arg0, int arg1) {
											// TODO Auto-generated method stub
											arg0.cancel();
										}
									}).show();

				}
			}
		});
	}

	private String getCity() {
		return citites[citySpinner.getSelectedItemPosition()];
	}

	private String getFavorite() {
		String favString = "";
		for (CheckBox cb : favorites) {
			if (cb.isChecked()) {
				favString += cb.getText().toString();
				favString += ",";
			}
		}
		if (favString != "") {
			favString = favString.substring(0, favString.length() - 1);
		} else {
			favString = "Please Select your favorite!";
		}
		return favString;
	}

	private String getSex() {
		RadioButton mRadio = (RadioButton) findViewById(sextRdoGrp
				.getCheckedRadioButtonId());
		return mRadio.getText().toString();
	}

	public boolean addUser() {
		if (name.getText().toString().length() == 0) {
			name.setError("Please input your name!");
			return false;
		}
		if (age.getText().toString().length() == 0) {
			age.setError("Please input your age!");
			return false;
		}
		if (pass.getText().toString().length() == 0) {
			pass.setError("Please input the password!");
			return false;
		}
		return true;
	}
}

2、main.xml

3、strings.xml

4、parameters.xml

UserLogin

暂无评论
  • 1:请一针见血的评论。
  • 2:评论需要审核通过后才能显示。
  • 3:评论字数限制在1000字以内。
  • 当前字数:0
热门文章
推荐文章
随机文章