- còn đây là của sinhvien_item_layout.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| <?xml version="1.0" encoding="utf-8"?> android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" ><TextView android:id="@+id/txtMaVaTen" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="15sp" /><TextView android:id="@+id/txtThongTinKhac" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#800000" android:textSize="10sp" android:textStyle="italic" /></LinearLayout> |
-3 -Bạn xem cấu trúc class xử lý nghiệp vụ:
- class Student:
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
| package tranduythanh.com;import java.util.Date;/** * Class dùng để lưu trữ thông tin của sinh viên * id: Mã * name: Tên * gender: giới tính, true là nữ * birthday: lưu năm sinh * placeOfBirth: nơi sinh * @author drthanh * */public class Student { private String id; private String name; private boolean gender; private Date birthday; private String placeOfBirth; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public boolean isGender() { return gender; } public void setGender(boolean gender) { this.gender = gender; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getPlaceOfBirth() { return placeOfBirth; } public void setPlaceOfBirth(String placeOfBirth) { this.placeOfBirth = placeOfBirth; } public Student(String id, String name, boolean gender, Date birthday, String placeOfBirth) { super(); this.id = id; this.name = name; this.gender = gender; this.birthday = birthday; this.placeOfBirth = placeOfBirth; } public Student() { super(); }} |
- 4 class MyArrayAdapter (class dùng để Custom Listview):
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
| package tranduythanh.com;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Locale;import android.app.Activity;import android.view.View;import android.view.ViewGroup;import android.widget.ArrayAdapter;import android.widget.TextView;/** * Đây là class dùng để custom layout * Bạn đã được học trước đó * Class này sẽ lấy layout: sinhvien_item_layout.xml * @author drthanh * */public class MyArrayAdapter extends ArrayAdapter<Student> {Activity context; int resourceId; ArrayList<Student>arrStudent; public MyArrayAdapter(Activity context, int resource, ArrayList<Student> objects) { super(context, resource, objects); this.context=context; this.resourceId=resource; this.arrStudent=objects; } @Override public View getView(int position, View convertView, ViewGroup parent) { if(convertView==null) { //gắn Layout vào Activity convertView= context.getLayoutInflater().inflate(resourceId, null); } //Lấy Textview để lưu mã và tên TextView txtMaTen=(TextView) convertView.findViewById(R.id.txtMaVaTen); //Lấy TextView để lưu giới tính, năm sinh, nơi sinh TextView txtKhac=(TextView) convertView.findViewById(R.id.txtThongTinKhac); //Lấy sinh viên thứ position Student s=arrStudent.get(position); txtMaTen.setText(s.getId()+" - "+s.getName()); //Dùng SimpleDateFormat để định dạng ngày tháng dd/MM/YYYY -> 22/12/2012 SimpleDateFormat dft=new SimpleDateFormat("dd/MM/yyyy",Locale.getDefault()); txtKhac.setText((s.isGender()?"Nữ-":"Nam-")+ dft.format(s.getBirthday())+" - "+ s.getPlaceOfBirth()); return convertView; }} |
Xem tiếp P3...
0 nhận xét:
Đăng nhận xét