Bài 25 : Củng Cố Kiến Thức Intent Qua Ví Dụ Quản Lý Nhân Viên (P5)

Leave a Comment
- Coding NhanVienAdapter.java, Ở phòng ban Tôi không sử dụng ImageView, còn ở Nhân viên Tôi sử dụng ImageView :
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
package tranduythanh.com.adapter;
 
import java.util.ArrayList;
 
import tranduythanh.com.activity.R;
import tranduythanh.com.model.NhanVien;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Class để tạo customlayout cho danh sách nhân viên
 * ImageVIew để hiển thị hình ảnh theo giới tính
 * @author drthanh
 *
 */
public class NhanVienAdapter extends ArrayAdapter<NhanVien> {
 
Activity context;
 int layoutId;
 ArrayList<NhanVien> arrNhanVien;
 public NhanVienAdapter(Activity context, int textViewResourceId,
 ArrayList<NhanVien> objects) {
 super(context, textViewResourceId, objects);
 this.context=context;
 this.layoutId=textViewResourceId;
 this.arrNhanVien=objects;
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
 //gán XML layout vào coding
 convertView=context.getLayoutInflater().inflate(layoutId, null);
 //lấy các control ra
 TextView txtnv= (TextView) convertView.findViewById(R.id.txtShortInfor);
 TextView txtmotanv= (TextView) convertView.findViewById(R.id.txtDetailInfor);
 ImageView img=(ImageView) convertView.findViewById(R.id.imgview);
 //lấy nhân viên thứ position
 NhanVien nv=arrNhanVien.get(position);
 txtnv.setText(nv.toString());
 String strMota="";
 String cv="Chức vụ: "+nv.getChucvu().getChucVu();
 String gt="Giới tính: "+(nv.isGioitinh()?"Nữ":"Nam");
 //Kiểm tra giới tính để gán cho đúng hình đại diện
 img.setImageResource(R.drawable.girlicon);
 if(!nv.isGioitinh())
 img.setImageResource(R.drawable.boyicon);
 strMota=cv+"\n"+gt;
 txtmotanv.setText(strMota);
 return convertView;
 }
 
}
- Bây giờ ta qua package tranduythanh.com.activity:
25_intent_20
- Ta lần lượt vào từng màn hình theo thứ tự.
- Màn hình chính (MainActivity.java):
- Bạn xem Outline của màn hình chính chính:
25_intent_22
- Đây là XML source của MainActivity:
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
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/LinearLayout1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 tools:context=".MainActivity" >
 
<TextView
 android:id="@+id/textView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="#008000"
 android:gravity="center"
 android:text="Chương trình quản lý nhân viên"
 android:textColor="#FFFFFF"
 android:textSize="20sp" />
 
<TableLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:stretchColumns="*"
 >
 
<TableRow
 android:id="@+id/tableRow1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
 
<TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Mã Phòng Ban:" />
 
<EditText
 android:id="@+id/editmapb"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:ems="10" >
 
<requestFocus />
 </EditText>
 
</TableRow>
 
<TableRow
 android:id="@+id/tableRow2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
 
<TextView
 android:id="@+id/textView3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="Tên Phòng Ban:" />
 
<EditText
 android:id="@+id/editTenpb"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:ems="10" />
 
</TableRow>
 
<TableRow
 android:id="@+id/tableRow3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >
 
<Button
 android:id="@+id/btnluupb"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_column="1"
 android:text="Lưu Phòng Ban" />
 
</TableRow>
 </TableLayout>
 
<TextView
 android:id="@+id/textView4"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="#008000"
 android:text="Danh sách phòng ban"
 android:textColor="#FFFFFF"
 android:textSize="15sp" />
 
<ListView
 android:id="@+id/lvphongban"
 android:layout_width="match_parent"
 android:layout_height="wrap_content" >
 </ListView>
 
</LinearLayout>
Xem tiếp P5

0 nhận xét:

Đăng nhận xét