关闭

Android学习笔记:SQLite的使用

标签: AndroidADBSQLite
1523人阅读 评论(1) 收藏 举报
分类:
本周作业难过花了好几天研究呢
使用Sqlite存储数据技术,开发一个简单的学生信息管理Android程序,要求如下:
1)设计一个描述学生姓名、性别、年龄、所在班级名称、班主任姓名的数据库。
2)绘制数据库的ER图。
3)使用SqliteManager及类似的软件建立数据库,并把数据库文件复制到手机内部存储器中。
4)实现学生的增、删、改、查(通过姓名查找学生的班主任姓名)

总体学习要点:
1.了解SQLite的基本语法,学习本地测试SQLite
2.了解Android使用SQLite的方法 包括 数据库初始化 数据库连接 数据库执行命令 获取查询结果

效果图:
0-1.运行默认界面

0-2.菜单效果

0-3.添加模式

0-4.删除模式-长按删除

0-5.修改模式

0-6.查找界面


实现步骤:
一.设计数据库和ER图
数据库设计

2.ER图-Visio2013画 不过没有给出属性


二.学习本地调试SQLite测试自己的SQLite语法
1.SQLite是一个轻量级数据库,从官网下载回来只要几百K而已 所以任何一款SQLite图形界面管理工具,都自带且包含了SQLite 无需额外安装
2.个人推荐Navicat For SQLite 

可以测试自己的语法有没有问题,这很重要,影响到程序中执行SQL语法的正确性,在本地测试好SQL语句 以免在程序运行中抛出各种神奇的异常

三.学会用ADB查看 自己Android设备里面的数据库
1.Win+R 输入cmd打开命令行
2.根据上一篇文章提及的配置 http://blog.csdn.net/theloneranger/article/details/17081509
使得能用adb进入Android设备里面的Shell
查看设备

进入shell

输入sqlite3 进入sqlite 模式

这里可以查看 设备上的数据库

四.SQLite使用注意事项
1.我们在使用数据库的时候,如果把连接数据库的语句全都写在第一个Activity里面,那么每次启动应用程序,就会(创建)初始化一次数据库,这样很容易出错
所以要用一个 新的初始化数据库的类 来继承Andorid本来就有的SQLiteHelper类
通过重写SQLiteHelper类里面的onCreate 和onUpgrade 方法 达到 第一次启动程序 使用onCreate 创建数据库并且初始化里面内容,第二次启动发现数据库存在,就不再调用onCreate方法 而是改用onUpgrade方法了.
2.Java里面链接数据库 我们用的是ResultSet 来保存执行有返回结果的查询语句
对于SQLite 我们使用的是一种叫做游标的东西 即Cursor
Cursor c= DB.rawQuery("Select * From 'student'",null);        //意思是将执行 "Select * From 'student'"这条语句返回的结果存在 一个类似ResultSet的集合里面
而游标 c默认指向这个集合的一个列
具体访问方法:
Cursor c=DBO.getCursor(SearchSQL);
c.moveToFirst();
while(!c.isAfterLast()){
	ShowAnswer=c.getString(0).toString();
	c.moveToNext();}

五.实现代码
1.整体类图


2.类代码
StarMenu.java
package com.example.studmnt;

import java.util.ArrayList;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class StarMenu extends Activity {
	public DBHelper DBHelper;
	public SQLiteDatabase DB;
	public ListView AllMsg;
	public ArrayList<ArrayList<String>>Info=new ArrayList<ArrayList<String>>();
	public ArrayList<String> StudName = new ArrayList<String>();
	public ArrayAdapter<String> adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.startpage);
		AllMsg=(ListView)this.findViewById(R.id.StudentShow);
		 adapter= new ArrayAdapter<String>(
				this, android.R.layout.simple_list_item_1,StudName );
		ConnectSQL();
		GetStudInfo();
		SetAdapter();
	}
	private void ClearStudInfo(){
		Info.clear();
		StudName.clear();
		
	}
	private void GetStudInfo() {
		DBOperation DBO=new DBOperation(this);
		String SQL="Select * From 'Student';";
		Cursor CStudInfo=DBO.getCursor(SQL);
		CStudInfo.moveToFirst();
		while(!CStudInfo.isAfterLast()){
			ArrayList<String> SubInfo = new ArrayList<String>();
			String Name=CStudInfo.getString(0);
			String Sex=CStudInfo.getString(1);
			int Age=CStudInfo.getInt(2);
			String ClassName=CStudInfo.getString(3);
			SubInfo.add(Name);
			SubInfo.add(Sex);
			SubInfo.add(String.valueOf(Age));
			SubInfo.add(ClassName);
			StudName.add(Name);
			Info.add(SubInfo);
			CStudInfo.moveToNext();
		}
	}
	private void SetAdapter(){
		AllMsg.setAdapter(adapter);
		AllMsg.setOnItemClickListener(new OnItemClickListener(){
			@SuppressLint("ShowToast")
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				
				Toast toast=Toast.makeText(getBaseContext(),""+Info.get(arg2), 1000);
				toast.show();
			}
			
		});
	}
	@Override
	//添加默认菜单 增 删 改 查
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(Menu.NONE, 1, 0, "增");
		menu.add(Menu.NONE, 2, 0, "删");
		menu.add(Menu.NONE, 3, 0, "改");
		menu.add(Menu.NONE, 4, 0, "查");
		return super.onCreateOptionsMenu(menu);
	}
	
	//添加跳传方法
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		/* case必须为常量 */
		case 1: {
			Intent JtoAdd=new Intent(this,AddInfo.class);
			startActivity(JtoAdd);
			break;
		}
		case 2: {
			Intent JtoDel=new Intent(this,DelInfo.class);
			startActivity(JtoDel);
			break;
		}
		case 3: {
			Intent JtoUpd=new Intent(this,UpdateInfo.class);
			startActivity(JtoUpd);
			break;
		}
		case 4: {
			Intent JtoSrh=new Intent(this,SearchInfo.class);
			startActivity(JtoSrh);
			break;
		}
		}
		return super.onOptionsItemSelected(item);

	}
	
	@Override
    protected void onResume()
    {
            super.onResume();
            ClearStudInfo();
            GetStudInfo();
            SetAdapter();
            // 刷新方法
    }
	//初始化连接
	public void ConnectSQL(){
		DBHelper=new DBHelper(this);
		Toast.makeText(getBaseContext(), "数据库初始化成功!", Toast.LENGTH_LONG).show();
		
	}
}

DBHelper.java
package com.example.studmnt;

import java.util.ArrayList;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	private static final String DBName = "StudentInfo.db";// 数据库名称
	private static final int DBVersion = 1;// 数据库版本

	public DBHelper(Context context) {
		super(context, DBName, null, DBVersion);

	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String StCreate = "CREATE TABLE IF NOT EXISTS Student('Name' varchar(20) NOT NULL PRIMARY KEY,'Sex' varchar(10) NOT NULL,'Age' int NOT NULL,'ClassName' varchar(20) NOT NULL,CONSTRAINT 'fkey0' FOREIGN KEY ('ClassName') REFERENCES 'Class' ('ClassName'));";
		String TCreate = "CREATE TABLE Class('ClassName' varchar(20) NOT NULL PRIMARY KEY,'TeacherName' varchar(20) NOT NULL);";
		//String InitTeacher = "INSERT INTO 'Class' VALUES ('11软件1班', '吕威');INSERT INTO 'Class' VALUES ('11软件2班', '吕小威');INSERT INTO 'Class' VALUES ('11软件3班', '陈静');INSERT INTO 'Class' VALUES ('11电子1班', '赖海婷');";
		db.execSQL(StCreate);
		db.execSQL(TCreate);
		//db.execSQL(InitTeacher);
		//班主任数据初始插入
		ArrayList<String> ISQL=new ArrayList<String>();
		ISQL.add("INSERT INTO 'Class' VALUES ( '11软件1班','吕威');");
		ISQL.add("INSERT INTO 'Class' VALUES ( '11软件2班','马明');");
		ISQL.add("INSERT INTO 'Class' VALUES ( '11电气1班','空口烟');");
		ISQL.add("INSERT INTO 'Class' VALUES ( '11电子1班','汪洪洋');");
		ISQL.add("INSERT INTO 'Class' VALUES ( '11数媒1班','陈浩南');");
		ISQL.add("INSERT INTO 'Class' VALUES ( '11计算机1班','司徒浩南');");
		ISQL.add("INSERT INTO 'Class' VALUES ( '11网络1班','孙耀阳');");
		ISQL.add("INSERT INTO 'Class' VALUES ( '11特工1班','陈玄冰');");
		ISQL.add("INSERT INTO 'Class' VALUES ( '12软件1班','汪可盈');");
		for(int i=0;i<ISQL.size();i++){
			db.execSQL(ISQL.get(i));
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// 木有方法
	}

}

DBOperation.java
package com.example.studmnt;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
@SuppressWarnings("unused")
public class DBOperation {
	private static final String DBName="StudentInfo.db";
	private static final String CTable="Class";
	
	private static final String STable="Student";
	
	private SQLiteDatabase DB;
	private Context context;
	private DBHelper DBH;
	public DBOperation(Context c){
		this.context=c;
		DBH=new DBHelper(this.context);
		DB=DBH.getWritableDatabase();
	}
	public void Insert(String SQL){
		DB.execSQL(SQL);
	}
	public int getInfoCount(){
		Cursor CStudent = DB.rawQuery("Select * From 'student'",null);
		int Count=CStudent.getCount();
		return Count;
	}
	
	public Cursor getCursor(String SQL){
		Cursor CStudent=DB.rawQuery(SQL, null);
		return CStudent;
	}
	public void Close(){
		if(DB!=null){
			DB.close();
			DB=null;
		}
	}
}

AddInfo.java
package com.example.studmnt;



import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
public class AddInfo extends Activity implements OnCheckedChangeListener,OnClickListener{
	private EditText EName,EClassName,EAge;
	private RadioGroup SexGroup;
	private String Sex;
	private RadioButton Man,Woman;
	private Button Confirm,Reset;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add);
		//实例化部分
		EName=(EditText)findViewById(R.id.InputName);
		EClassName=(EditText)findViewById(R.id.InputClassName);
		EAge=(EditText)findViewById(R.id.InputAge);
		SexGroup=(RadioGroup)findViewById(R.id.SexGroup);
		Sex="男";
		Man = (RadioButton) findViewById(R.id.Man);  
        Woman = (RadioButton) findViewById(R.id.Woman);  
        Confirm=(Button)findViewById(R.id.Confirm);
        Reset=(Button)findViewById(R.id.Reset);
        //添加监听器部分
        SexGroup.setOnCheckedChangeListener(this);  
        Confirm.setOnClickListener(new OnClickListener(){
        	public void onClick(View view){
        		OnClickConfirm();
        	}
        });
        Reset.setOnClickListener(new OnClickListener(){
        	public void onClick(View view){
        		OnClickReset();
        	}
        });
	}
	//男女单选监听器
	@Override
	public void onCheckedChanged(RadioGroup SexGroup, int CheckedId) {
		if(CheckedId == Woman.getId()){
			Sex="女";
		}
		else if(CheckedId==Man.getId()){
			Sex="男";
		}
	}
	//Reset方法
	public void OnClickReset(){
		EName.setText(null);
		EAge.setText(null);
		EClassName.setText(null);
	}
	public void OnClickConfirm(){
		String Name=EName.getText().toString();
		int Age=Integer.parseInt(EAge.getText().toString());
		String ClassName=EClassName.getText().toString();
		DBOperation DB=new DBOperation(this);
		int C1=DB.getInfoCount();
		String SQL="INSERT INTO `student` VALUES ('"+Name+"', '"+Sex+"', '"+Age+"', '"+ClassName+"');";
		try{
			DB.Insert(SQL);
		}catch(Exception e){
			Toast.makeText(this, "添加失败!", Toast.LENGTH_LONG).show();
		}
		int C2=DB.getInfoCount();
		if(C2>C1){
			Toast.makeText(this, "添加成功!", Toast.LENGTH_LONG).show();
		}
		OnClickReset();
	}
	@Override
	public void onClick(View V) {
	}
}

DelInfo.java
package com.example.studmnt;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class DelInfo extends Activity {
	public DBHelper DBHelper;
	public SQLiteDatabase DB;
	public ListView AllMsg;
	public ArrayList<ArrayList<String>>Info=new ArrayList<ArrayList<String>>();
	public ArrayList<String> StudName = new ArrayList<String>();
	public ArrayAdapter<String> adapter;
	public Context context;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.startpage);
		AllMsg=(ListView)this.findViewById(R.id.StudentShow);
		 adapter= new ArrayAdapter<String>(
				this, android.R.layout.simple_list_item_1,StudName );
		context=this;
		ConnectSQL();
		GetStudInfo();
		SetAdapter();
		
	}
	@SuppressWarnings("unused")
	private void ClearStudInfo(){
		Info.clear();
		StudName.clear();
	}
	private void GetStudInfo() {
		DBOperation DBO=new DBOperation(this);
		String SQL="Select * From 'Student';";
		Cursor CStudInfo=DBO.getCursor(SQL);
		CStudInfo.moveToFirst();
		while(!CStudInfo.isAfterLast()){
			ArrayList<String> SubInfo = new ArrayList<String>();
			String Name=CStudInfo.getString(0);
			String Sex=CStudInfo.getString(1);
			int Age=CStudInfo.getInt(2);
			String ClassName=CStudInfo.getString(3);
			SubInfo.add(Name);
			SubInfo.add(Sex);
			SubInfo.add(String.valueOf(Age));
			SubInfo.add(ClassName);
			StudName.add(Name);
			Info.add(SubInfo);
			CStudInfo.moveToNext();
		}
		DBO.Close();
	}
	private void SetAdapter(){
		AllMsg.setAdapter(adapter);
		AllMsg.setOnItemClickListener(new OnItemClickListener(){
			@SuppressLint("ShowToast")
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				
				Toast toast=Toast.makeText(getBaseContext(),""+Info.get(arg2), 1000);
				toast.show();
			}
			
		});
		AllMsg.setOnItemLongClickListener(new OnItemLongClickListener(){

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				ArrayList<String>TInfo=Info.get(arg2);
				String Name=TInfo.get(0);
				DBOperation DBO=new DBOperation(context);
				String DelSQL="Delete From 'Student' Where Name ="+"'"+Name+"'"+";";
				try{
					DBO.Insert(DelSQL);
				}catch(Exception e){
					Toast.makeText(context, "删除失败", Toast.LENGTH_LONG).show();
				}
				refresh(); 
				return true;
			}
			
		});
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return super.onCreateOptionsMenu(menu);
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
		
		return super.onOptionsItemSelected(item);

	}
	private void refresh() {  
        finish();  
        Intent intent = new Intent(DelInfo.this,DelInfo.class);  
        startActivity(intent);  
    }  
	

	//初始化连接
	public void ConnectSQL(){
		DBHelper=new DBHelper(this);
		//Toast.makeText(getBaseContext(), "数据库初始化成功!", Toast.LENGTH_LONG).show();
		
	}
	
	
}

Update.java
package com.example.studmnt;

import android.app.Activity;
import android.os.Bundle;

import android.view.View;
import android.view.View.OnClickListener;

import android.widget.Button;
import android.widget.EditText;

import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class UpdateInfo extends Activity implements OnCheckedChangeListener,OnClickListener{
	private EditText EName,EClassName,EAge;
	private RadioGroup SexGroup;
	private String Sex;
	private RadioButton Man,Woman;
	private Button Confirm,Reset;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.update);
		//实例化部分
		EName=(EditText)findViewById(R.id.InputName);
		EClassName=(EditText)findViewById(R.id.InputClassName);
		EAge=(EditText)findViewById(R.id.InputAge);
		SexGroup=(RadioGroup)findViewById(R.id.SexGroup);
		Sex="男";
		Man = (RadioButton) findViewById(R.id.Man);  
        Woman = (RadioButton) findViewById(R.id.Woman);  
        Confirm=(Button)findViewById(R.id.Confirm);
        Reset=(Button)findViewById(R.id.Reset);
        //添加监听器部分
        SexGroup.setOnCheckedChangeListener(this);  
        Confirm.setOnClickListener(new OnClickListener(){
        	public void onClick(View view){
        		OnClickConfirm();
        	}
        });
        Reset.setOnClickListener(new OnClickListener(){
        	public void onClick(View view){
        		OnClickReset();
        	}
        });
	}
	//男女单选监听器
	@Override
	public void onCheckedChanged(RadioGroup SexGroup, int CheckedId) {
		if(CheckedId == Woman.getId()){
			Sex="女";
		}
		else if(CheckedId==Man.getId()){
			Sex="男";
		}
	}
	//Reset方法
	public void OnClickReset(){
		EName.setText(null);
		EAge.setText(null);
		EClassName.setText(null);
	}
	public void OnClickConfirm(){
		String Name=EName.getText().toString();
		int Age=Integer.parseInt(EAge.getText().toString());
		String ClassName=EClassName.getText().toString();
		DBOperation DB=new DBOperation(this);
		int C1=DB.getInfoCount();
		String SQL="UPDATE 'Student' SET Age="+Age+",Sex='"+Sex+"',ClassName='"+ClassName+"' WHERE Name = '"+Name+"';";
		try{
			DB.Insert(SQL);
		}catch(Exception e){
			Toast.makeText(this, "修改失败!", Toast.LENGTH_LONG).show();
		}
		int C2=DB.getInfoCount();
		if(C2==C1){
			Toast.makeText(this, "修改成功!", Toast.LENGTH_LONG).show();
		}
		OnClickReset();
	}
	@Override
	public void onClick(View V) {
	}
}

SearchInfo.java
package com.example.studmnt;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
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;
import android.widget.Toast;

public class SearchInfo extends Activity{
	private Button SearchConfirm;
	private TextView Answer;
	private EditText ESearch;
	private Context context;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search);
		context=this;
		SearchConfirm =(Button)findViewById(R.id.Search);
		Answer =(TextView)findViewById(R.id.Answer);
		ESearch=(EditText)findViewById(R.id.InputSearch);
		SearchConfirm.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				DBOperation DBO=new DBOperation(context);
				String ShowAnswer="";
				String SubInfo=ESearch.getText().toString();
				String SearchSQL="SELECT TeacherName FROM Student,Class WHERE Student.ClassName = Class.ClassName AND Student.Name like '%"+SubInfo+"%';";
				try{
					Cursor c=DBO.getCursor(SearchSQL);
					c.moveToFirst();
					while(!c.isAfterLast()){
						ShowAnswer=c.getString(0).toString();
						c.moveToNext();
					}
				}catch(Exception e){
					Toast.makeText(context, "无法查询", Toast.LENGTH_LONG).show();
				}
				Answer.setText(ShowAnswer);
				if(ShowAnswer.equals("")){
					Answer.setText("搜索关键词有误,找不到该相关的班主任姓名");
				}
			}
			
		});
	}
}



3.部分界面代码
startpage.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".StarMenu" >
<ListView
        android:id="@+id/StudentShow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

    </ListView>
   
</RelativeLayout>

add.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/SName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="49dp"
        android:layout_toLeftOf="@+id/InputName"
        android:text="@string/Name" />

    <EditText
        android:id="@+id/InputName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/SName"
        android:layout_alignBottom="@+id/SName"
        android:layout_centerHorizontal="true"
        android:ems="10"
        android:inputType="text" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/SAge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/InputName"
        android:layout_marginTop="32dp"
        android:layout_toLeftOf="@+id/InputName"
        android:text="@string/Age" />

    <EditText
        android:id="@+id/InputAge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/SAge"
        android:layout_alignBottom="@+id/SAge"
        android:layout_alignLeft="@+id/InputName"
        android:ems="10"
        android:inputType="number" />

    <TextView
        android:id="@+id/SSex"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/SAge"
        android:layout_below="@+id/InputAge"
        android:layout_marginTop="32dp"
        android:text="@string/Sex" />

    <EditText
        android:id="@+id/InputClassName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/SClass"
        android:layout_alignBottom="@+id/SClass"
        android:layout_alignLeft="@+id/InputAge"
        android:ems="10"
        android:inputType="text" />

    <Button
        android:id="@+id/Reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/InputClassName"
        android:layout_marginBottom="64dp"
        android:layout_marginRight="16dp"
        android:text="@string/Reset" />

    <Button
        android:id="@+id/Confirm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/Reset"
        android:layout_alignBottom="@+id/Reset"
        android:layout_alignLeft="@+id/InputClassName"
        android:text="@string/AddConfrim" />

    <RadioGroup
        android:id="@+id/SexGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/SSex"
        android:layout_marginRight="36dp"
        android:layout_toLeftOf="@+id/Reset" >

        <RadioButton
            android:id="@+id/Man"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/Man" />
        
        <RadioButton
        android:id="@+id/Woman"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Woman" />
        
    </RadioGroup>

    <TextView
        android:id="@+id/SClass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/SSex"
        android:layout_centerVertical="true"
        android:text="@string/ClassName" />

    
</RelativeLayout>


详情可以下载我的资源 http://download.csdn.net/detail/u011501908/6667863

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:32563次
    • 积分:520
    • 等级:
    • 排名:千里之外
    • 原创:19篇
    • 转载:0篇
    • 译文:0篇
    • 评论:19条
    文章分类
    最新评论