來(lái)源:Andr_Robot 發(fā)布時(shí)間:2018-11-30 17:41:15 閱讀量:1105
最近學(xué)習(xí)Android,做了一些小的東西,一直沒(méi)有時(shí)間做個(gè)總結(jié)。經(jīng)常總結(jié)對(duì)于學(xué)習(xí)新東西是很好的,說(shuō)以今天整理一下自己做的東西,希望這樣也有助于其他人學(xué)習(xí)。
我做的是一個(gè)基于Android平臺(tái),使用SQLite構(gòu)建數(shù)據(jù)庫(kù),并且創(chuàng)建表來(lái)存儲(chǔ)數(shù)據(jù),還會(huì)涉及到數(shù)據(jù)的增刪查改。整體的效果圖如下:
上面就是Demo在調(diào)試時(shí)的幾幅圖,下面將會(huì)一一介紹這個(gè)Demo中用到的一些核心技術(shù)。
首先就是用到了SQLiteOpenHelper這個(gè)類,通過(guò)創(chuàng)建一個(gè)自己的幫助類來(lái)繼承這個(gè)抽象類,來(lái)實(shí)現(xiàn)簡(jiǎn)單的對(duì)數(shù)據(jù)庫(kù)創(chuàng)建和升級(jí)。SQLiteOpenHelper中有兩個(gè)抽象方法,分別是onCreate()和onUpgrade(),我們必須在自己的幫助類里面重寫(xiě)這兩個(gè)方法,然后分別在這兩個(gè)方法中去實(shí)現(xiàn)創(chuàng)建、升級(jí)數(shù)據(jù)庫(kù)的邏輯。SQLiteOpenHelper中有兩個(gè)非常重要的實(shí)例方法,getReadableDatabase()和getWritableDatabase()。這兩個(gè)方法都可以創(chuàng)建和打開(kāi)一個(gè)現(xiàn)有的數(shù)據(jù)庫(kù)(如果數(shù)據(jù)庫(kù)已經(jīng)存在則直接打開(kāi),否則創(chuàng)建一個(gè)新的數(shù)據(jù)庫(kù)),并返回一個(gè)可對(duì)數(shù)據(jù)庫(kù)進(jìn)行讀寫(xiě)操作的對(duì)象。不同的是,當(dāng)數(shù)據(jù)庫(kù)不可寫(xiě)入的時(shí)候(如磁盤空間已滿)getReadabelDatabase()方法返回的對(duì)象將以只讀的方式去打開(kāi)數(shù)據(jù)庫(kù),而getWritableDatabase()方法則會(huì)出現(xiàn)異常。
MyDatabaseHelper.java
public class MyDatabaseHelper extends SQLiteOpenHelper {
private static final String CREATE_TABLE = "create table peopleinfo (_id integer primary key autoincrement,name text not null,age integer,height float);";
private Context mContext;
public MyDatabaseHelper(Context context, String name,
CursorFactory factory, int version) {
super(context, name, factory, version);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists peopleinfo");
onCreate(db);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
“drop table if exists peopleinfo”這句代碼的作用就是當(dāng)發(fā)現(xiàn)數(shù)據(jù)庫(kù)中已經(jīng)存在peopleinfo表,就將這兩個(gè)表刪除掉 ,然后調(diào)用onCreate()方法去重新創(chuàng)建。
構(gòu)建People用來(lái)存儲(chǔ)輸入的People信息,方便向數(shù)據(jù)庫(kù)中存儲(chǔ)。
People.java
public class People {
public int ID;
public String Name;
public int Age;
public float Height;
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public int getAge() {
return Age;
}
public void setAge(int age) {
Age = age;
}
public float getHeight() {
return Height;
}
public void setHeight(float height) {
Height = height;
}
@Override
public String toString(){
String result = "";
result += "ID:" + this.ID + ",";
result += "姓名:" + this.Name + ",";
result += "年齡:" + this.Age + ", ";
result += "身高:" + this.Height ;
return result;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
activity_main.xml:主界面的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="姓名:"
android:textSize="23sp"/>
<EditText
android:id="@+id/edt_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="請(qǐng)輸入姓名"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="年齡:"
android:textSize="23sp"/>
<EditText
android:id="@+id/edt_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numeric="integer"
android:hint="請(qǐng)輸入年齡"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="身高:"
android:textSize="23sp"/>
<EditText
android:id="@+id/edt_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numeric="decimal"
android:hint="請(qǐng)輸入身高"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<Button
android:id="@+id/bt_adddata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="添加數(shù)據(jù)"
android:textSize="12sp"
android:layout_weight="1"/>
<Button
android:id="@+id/bt_showalldata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全部顯示"
android:textSize="12sp"
android:layout_weight="1"/>
<Button
android:id="@+id/bt_clearshowdata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="清除顯示"
android:textSize="12sp"
android:layout_weight="1"/>
<Button
android:id="@+id/bt_deletealldata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全部刪除"
android:textSize="12sp"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ID:"
android:textSize="23sp"/>
<EditText
android:id="@+id/edt_id"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:numeric="integer"
android:layout_weight="1"/>
<Button
android:id="@+id/bt_deteleid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ID刪除"
android:textSize="12sp"
android:layout_weight="1"/>
<Button
android:id="@+id/bt_queryid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ID查詢"
android:textSize="12sp"
android:layout_weight="1"/>
<Button
android:id="@+id/bt_updateid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ID更新"
android:textSize="12sp"
android:layout_weight="1"/>
</LinearLayout>
<TextView
android:layout_margin="10dp"
android:id="@+id/txt_sjk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="數(shù)據(jù)庫(kù):"
android:textSize="23sp"/>
<ListView
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/listview_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
MainActivity.java
public class MainActivity extends Activity implements OnClickListener {
private MyDatabaseHelper dbHelper;
private SQLiteDatabase db;
private EditText edt_Name;
private EditText edt_Age;
private EditText edt_Height;
private EditText edt_Id;
private Button bt_AddData;
private Button bt_ShowAllData;
private Button bt_ClearShowData;
private Button bt_DeleteAllData;
private Button bt_DeleteById;
private Button bt_QueryById;
private Button bt_UpdateById;
private ListView listview_show;
private String strName = "";
private String strAge = "";
private String strHeight = "";
private int m_Id;
private List<People> PeopleList = new ArrayList<People>();
private MyAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbHelper = new MyDatabaseHelper(this, "people.db", null, 1);
db = dbHelper.getWritableDatabase();
// 初始化控件
initShow();
// 添加數(shù)據(jù)
bt_AddData.setOnClickListener(this);
// 全部顯示
bt_ShowAllData.setOnClickListener(this);
// 清楚顯示
bt_ClearShowData.setOnClickListener(this);
// 全部刪除
bt_DeleteAllData.setOnClickListener(this);
// ID刪除
bt_DeleteById.setOnClickListener(this);
// ID查詢
bt_QueryById.setOnClickListener(this);
// ID更新
bt_UpdateById.setOnClickListener(this);
}
// 初始化控件
private void initShow() {
edt_Name = (EditText) findViewById(R.id.edt_name);
edt_Age = (EditText) findViewById(R.id.edt_age);
edt_Height = (EditText) findViewById(R.id.edt_height);
edt_Id = (EditText) findViewById(R.id.edt_id);
bt_AddData = (Button) findViewById(R.id.bt_adddata);
bt_ShowAllData = (Button) findViewById(R.id.bt_showalldata);
bt_ClearShowData = (Button) findViewById(R.id.bt_clearshowdata);
bt_DeleteAllData = (Button) findViewById(R.id.bt_deletealldata);
bt_DeleteById = (Button) findViewById(R.id.bt_deteleid);
bt_QueryById = (Button) findViewById(R.id.bt_queryid);
bt_UpdateById = (Button) findViewById(R.id.bt_updateid);
listview_show = (ListView) findViewById(R.id.listview_show);
}
// listview顯示數(shù)據(jù)庫(kù)數(shù)據(jù)
private void showData() {
mAdapter = new MyAdapter(MainActivity.this,
android.R.layout.simple_list_item_1, PeopleList);
listview_show.setAdapter(mAdapter);
}
// 獲取edittext中輸入的ID
public int getEd_ID() {
if (!edt_Id.getText().toString().equals("")) {
String strId = edt_Id.getText().toString();
m_Id = Integer.parseInt(strId);
} else {
m_Id = -1;
}
return m_Id;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
// 添加數(shù)據(jù)
case R.id.bt_adddata:
addData();
edt_Name.setText("");
edt_Age.setText("");
edt_Height.setText("");
break;
// 全部顯示
case R.id.bt_showalldata:
showAllData();
showData();
break;
// 清楚顯示
case R.id.bt_clearshowdata:
clearListView();
showData();
break;
// 全部刪除
case R.id.bt_deletealldata:
deleteData();
showData();
break;
// ID刪除
case R.id.bt_deteleid:
m_Id = getEd_ID();
deleteById(m_Id);
showAllData();
showData();
edt_Id.setText("");
break;
// ID查詢
case R.id.bt_queryid:
m_Id = getEd_ID();
queryById(m_Id);
showData();
edt_Id.setText("");
break;
// ID更新
case R.id.bt_updateid:
m_Id = getEd_ID();
updateById(m_Id);
showData();
edt_Id.setText("");
break;
}
}
// ID更新
private void updateById(int mId) {
if (mId == -1) {
Toast.makeText(MainActivity.this, "請(qǐng)輸入ID號(hào)", Toast.LENGTH_SHORT)
.show();
} else {
// 先找到這條數(shù)據(jù)
db = dbHelper.getReadableDatabase();
final People people = new People();
List<People> tempList=new ArrayList<People>();
Cursor cursor = db.query("peopleinfo", null, "_id" + "=" + mId,
null, null, null, null);
if (cursor.moveToFirst()) {
do {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor
.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
float height = cursor.getFloat(cursor
.getColumnIndex("height"));
people.setID(id);
people.setName(name);
people.setAge(age);
people.setHeight(height);
tempList.add(people);
} while (cursor.moveToNext());
}
cursor.close();
if (tempList.size()==0) {
Toast.makeText(MainActivity.this, "數(shù)據(jù)庫(kù)中沒(méi)有這條信息",
Toast.LENGTH_SHORT).show();
} else {
// 彈出自定義的AlertDialog
LayoutInflater factory = LayoutInflater.from(this);
final View textChangeView = factory.inflate(R.layout.custom,
null);
final EditText editTextName = (EditText) textChangeView
.findViewById(R.id.cEdt_name);
final EditText editTextAge = (EditText) textChangeView
.findViewById(R.id.cEdt_age);
final EditText editTextHeight = (EditText) textChangeView
.findViewById(R.id.cEdt_height);
editTextName.setText(people.getName());
editTextAge.setText(Integer.toString(people.getAge()));
editTextHeight.setText(Float.toString(people.getHeight()));
AlertDialog.Builder ad = new AlertDialog.Builder(
MainActivity.this);
ad.setTitle("ID更新:");
ad.setIcon(android.R.drawable.ic_dialog_info);
ad.setView(textChangeView);
ad.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
ContentValues updateValues = new ContentValues();
strName = editTextName.getText().toString();
strAge = editTextAge.getText().toString();
strHeight = editTextHeight.getText().toString();
int iAge = Integer.parseInt(strAge);
float fHeight = Float.parseFloat(strHeight);
// 開(kāi)始組裝一條數(shù)據(jù)
updateValues.put("name", strName);
updateValues.put("age", iAge);
updateValues.put("height", fHeight);
db.update("peopleinfo", updateValues, "_id"
+ "=" + people.getID(), null);
Toast.makeText(MainActivity.this, "更新成功",
Toast.LENGTH_SHORT).show();
Cursor cursor = db.query("peopleinfo", null, "_id" + "=" + people.getID(),
null, null, null, null);
PeopleList.clear();
if (cursor.moveToFirst()) {
do {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor
.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
float height = cursor.getFloat(cursor
.getColumnIndex("height"));
people.setID(id);
people.setName(name);
people.setAge(age);
people.setHeight(height);
PeopleList.add(people);
} while (cursor.moveToNext());
}
cursor.close();
}
});
ad.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
}
});
ad.show();
}
}
}
// ID查詢
private void queryById(int mId) {
if (mId == -1) {
Toast.makeText(MainActivity.this, "請(qǐng)輸入ID號(hào)", Toast.LENGTH_SHORT)
.show();
} else {
db = dbHelper.getReadableDatabase();
People people = new People();
PeopleList.clear();
Cursor cursor = db.query("peopleinfo", null, "_id" + "=" + mId,
null, null, null, null);
if (cursor.moveToFirst()) {
do {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor
.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
float height = cursor.getFloat(cursor
.getColumnIndex("height"));
people.setID(id);
people.setName(name);
people.setAge(age);
people.setHeight(height);
PeopleList.add(people);
} while (cursor.moveToNext());
}
cursor.close();
if (PeopleList.size() == 0) {
Toast.makeText(MainActivity.this, "數(shù)據(jù)庫(kù)中沒(méi)有這條數(shù)據(jù)",
Toast.LENGTH_SHORT).show();
}
}
}
// ID刪除
private void deleteById(int mId) {
if (mId == -1) {
Toast.makeText(MainActivity.this, "請(qǐng)輸入ID號(hào)", Toast.LENGTH_SHORT)
.show();
} else {
db = dbHelper.getWritableDatabase();
People people = new People();
PeopleList.clear();
Cursor cursor = db.query("peopleinfo", null, "_id" + "=" + mId,
null, null, null, null);
if (cursor.moveToFirst()) {
do {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor
.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
float height = cursor.getFloat(cursor
.getColumnIndex("height"));
people.setID(id);
people.setName(name);
people.setAge(age);
people.setHeight(height);
PeopleList.add(people);
} while (cursor.moveToNext());
}
cursor.close();
if (PeopleList.size() == 0) {
Toast.makeText(MainActivity.this, "數(shù)據(jù)庫(kù)中沒(méi)有這條數(shù)據(jù)",
Toast.LENGTH_SHORT).show();
} else {
db.delete("peopleinfo", "_id" + "=" + mId, null);
Toast.makeText(MainActivity.this, "成功刪除" + mId + "這條數(shù)據(jù)",
Toast.LENGTH_SHORT).show();
}
}
}
// 全部刪除
private void deleteData() {
db = dbHelper.getWritableDatabase();
db.delete("peopleinfo", null, null);
PeopleList.clear();
Toast.makeText(MainActivity.this, "數(shù)據(jù)清除成功", Toast.LENGTH_SHORT).show();
}
// 清除顯示
private void clearListView() {
PeopleList.clear();
}
// 全部顯示
private void showAllData() {
PeopleList.clear();
Cursor cursor = db.query("peopleinfo", null, null, null, null, null,
null);
if (cursor.moveToFirst()) {
do {
People people = new People();
// 遍歷表
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
float height = cursor.getFloat(cursor.getColumnIndex("height"));
people.setID(id);
people.setName(name);
people.setAge(age);
people.setHeight(height);
PeopleList.add(people);
} while (cursor.moveToNext());
}
cursor.close();
if (PeopleList.size() == 0) {
Toast.makeText(MainActivity.this, "數(shù)據(jù)庫(kù)中沒(méi)有數(shù)據(jù)", Toast.LENGTH_SHORT)
.show();
}
}
// 添加數(shù)據(jù)
private void addData() {
if (edt_Name.getText().toString().equals("")
&& edt_Age.getText().toString().equals("")
&& edt_Height.getText().toString().equals("")) {
AlertDialog.Builder dialog = new AlertDialog.Builder(
MainActivity.this);
dialog.setTitle("Warn");
dialog.setMessage("請(qǐng)輸入完整信息");
dialog.setCancelable(false);
dialog.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
edt_Name.setText("");
edt_Age.setText("");
edt_Height.setText("");
}
});
dialog.show();
} else {
ContentValues values = new ContentValues();
strName = edt_Name.getText().toString();
strAge = edt_Age.getText().toString();
strHeight = edt_Height.getText().toString();
int iAge = Integer.parseInt(strAge);
float fHeight = Float.parseFloat(strHeight);
// 開(kāi)始組裝一條數(shù)據(jù)
values.put("name", strName);
values.put("age", iAge);
values.put("height", fHeight);
// 插入數(shù)據(jù)
db.insert("peopleinfo", null, values);
Toast.makeText(MainActivity.this, "數(shù)據(jù)添加成功", Toast.LENGTH_SHORT)
.show();
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
// 獲得當(dāng)前得到焦點(diǎn)的View,一般情況下就是EditText(特殊情況就是軌跡求或者實(shí)體案件會(huì)移動(dòng)焦點(diǎn))
View v = getCurrentFocus();
if (isShouldHideInput(v, ev)) {
hideSoftInput(v.getWindowToken());
}
}
return super.dispatchTouchEvent(ev);
}
/**
* 根據(jù)EditText所在坐標(biāo)和用戶點(diǎn)擊的坐標(biāo)相對(duì)比,來(lái)判斷是否隱藏鍵盤,因?yàn)楫?dāng)用戶點(diǎn)擊EditText時(shí)沒(méi)必要隱藏
*
* @param v
* @param event
* @return
*/
private boolean isShouldHideInput(View v, MotionEvent event) {
if (v != null && (v instanceof EditText)) {
int[] l = { 0, 0 };
v.getLocationInWindow(l);
int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left
+ v.getWidth();
if (event.getX() > left && event.getX() < right
&& event.getY() > top && event.getY() < bottom) {
// 點(diǎn)擊EditText的事件,忽略它。
return false;
} else {
return true;
}
}
// 如果焦點(diǎn)不是EditText則忽略,這個(gè)發(fā)生在視圖剛繪制完,第一個(gè)焦點(diǎn)不在EditView上,和用戶用軌跡球選擇其他的焦點(diǎn)
return false;
}
/**
* 多種隱藏軟件盤方法的其中一種
*
* @param token
*/
private void hideSoftInput(IBinder token) {
if (token != null) {
InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(token,
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
custom.xml:自定義布局文件 ,用在ID更新時(shí)彈出的AlertDialog中。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="姓名:"
android:textSize="23sp" />
<EditText
android:id="@+id/cEdt_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="請(qǐng)輸入姓名" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="年齡:"
android:textSize="23sp" />
<EditText
android:id="@+id/cEdt_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="請(qǐng)輸入年齡"
android:numeric="integer" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="身高:"
android:textSize="23sp" />
<EditText
android:id="@+id/cEdt_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="請(qǐng)輸入身高"
android:numeric="decimal" />
</LinearLayout>
</LinearLayout>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
這個(gè)Demo還是很簡(jiǎn)單的,我就不做過(guò)多的解釋了 。各位看了之后,有什么見(jiàn)解歡迎留言交流交流共同進(jìn)步。
---------------------
在線
客服
服務(wù)時(shí)間:周一至周日 08:30-18:00
選擇下列產(chǎn)品馬上在線溝通:
客服
熱線
7*24小時(shí)客服服務(wù)熱線
關(guān)注
微信
關(guān)注官方微信