- Ta qua màn hình chuyển phòng ban cho nhân viên:
- Bạn xem layout XML:
- Màn hình này là màn hình con của màn hình Xem danh sách nhân nhiên (lúc dùng Context Menu).
- Khi chọn nhân viên nào thì sẽ tiến hành mở màn hình chuyển phòng ban cho nhân viên đó.
- xem XML Resource:
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
| android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".ChuyenPhongBanActivity" ><TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#008000" android:text="Chọn phòng ban để chuyển" android:textColor="#FFFFFF" android:textSize="15sp" /><ListView android:id="@+id/lvphongban" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="3" > </ListView><ImageButton android:id="@+id/imgapply" android:layout_width="32dp" android:layout_height="32dp" android:layout_gravity="center" android:contentDescription="Thiết lập" android:src="@drawable/apply" /></LinearLayout> |
- Bạn xem xử lý coding cho phần chuyển phòng ban:
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
| package tranduythanh.com.activity;import java.util.ArrayList;import tranduythanh.com.model.NhanVien;import tranduythanh.com.model.PhongBan;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.View;import android.view.View.OnClickListener;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.ArrayAdapter;import android.widget.CheckedTextView;import android.widget.ImageButton;import android.widget.ListView;/** * Class dùng để xử lý chuyển phòng ban cho nhân viên * @author drthanh * */public class ChuyenPhongBanActivity extends Activity {ListView lvPb; private static ArrayList<PhongBan>arrPhongBan=null; ArrayAdapter<PhongBan>adapter; ImageButton btnApply; NhanVien nv=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chuyen_phong_ban); getFormWidgets(); //lấy nhân viên từ màn hình xem danh sách nhân viên Intent i=getIntent(); Bundle b= i.getBundleExtra("DATA"); nv=(NhanVien) b.getSerializable("NHANVIEN"); } /** * hàm lấy control theo id * đồng thời load toàn bộ danh sách phòng ban ở MainActivity * lên ListView để sử dụng * android.R.layout.simple_list_item_single_choice ->dùng Radio * Bắt buộc phải xử lý hàm: lvPb.setOnItemClickListener * để gán checked cho Radio */ public void getFormWidgets() { lvPb=(ListView) findViewById(R.id.lvphongban); btnApply=(ImageButton) findViewById(R.id.imgapply); arrPhongBan=MainActivity.getListPhongBan(); adapter=new ArrayAdapter<PhongBan> (this, android.R.layout.simple_list_item_single_choice, arrPhongBan); lvPb.setAdapter(adapter);lvPb.setOnItemClickListener(new OnItemClickListener() {boolean somethingChecked = false; @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { //hiển nhiên View arg1 là CheckedTextView if(somethingChecked){ CheckedTextView cv = (CheckedTextView) arg1; cv.setChecked(false);} CheckedTextView cv = (CheckedTextView) arg1; if(!cv.isChecked()) { cv.setChecked(true); arrPhongBan.get(arg2).themNv(nv); } somethingChecked=true; } }); //khi chọn nút Apply thì tiến hành đóng màn hình này //và truyền lệnh về cho DanhSachNhanVienACtivity btnApply.setOnClickListener(new OnClickListener() {@Override public void onClick(View arg0) { doApply();} }); } public void doApply() { setResult(MainActivity.CHUYENPHONG_THANHCONG); finish(); }} |
- Xem P12
0 nhận xét:
Đăng nhận xét