Android簡單的學生管理系統
阿新 • • 發佈:2019-01-27
(1)管理系統實現的功能主要是:學生、教師的註冊登入,和選課,以及修改學生的成績等基本簡單的功能,最主要的是實現一些Dialog的使用。
介面如下:
(2)主要程式碼如下:(個人留作筆記,如需要完整程式碼,在最下邊免費下載)
下邊是一個介面卡,介面卡是為了一個listvie進行設定值,其中載入的是一個itemview,介面卡中還是用了繼承的方法,用於通知介面卡進行更新。
public class CourseAdapter extends BaseAdapter {
private Context context;
private List<Course> coursetList;
public CourseAdapter(Context context, List<Course> coursetList) {
this.context = context;
this.coursetList = coursetList;
}
public int getCount() {
return coursetList.size();
}
public Object getItem(int position) {
return coursetList.get(position);
}
public long getItemId(int position) {
return position;
}
/**
* 通知adapter更新資料
*/
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null ) {
//這裡載入的每一個item條目的佈局檔案
convertView = LayoutInflater.from(context).inflate(
R.layout.student_score_item, null);
}
TextView tv_name = (TextView) convertView.findViewById(R.id.tv_name);
TextView tv_course = (TextView) convertView
.findViewById(R.id.tv_course);
TextView tv_score = (TextView) convertView.findViewById(R.id.tv_score);
// 獲得某一個位置的student
Course course = coursetList.get(position);
tv_name.setText(course.getStudentName() + "");
tv_course.setText(course.getCourseName() + "");
tv_score.setText(course.getCourseSocre() + "");
return convertView;
}
}
(3)還用到了Java的反射機制,結合工廠模式進行操作:
public class PersonFactory {
/**
* 根據類的名稱來生產物件:java的反射機制使用
*
* @param className
* @return
*/
public PersonInter getPersonByClass(String className) {
try {
PersonInter personInter = (PersonInter) Class.forName(className).newInstance();
return personInter;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
/**
* 根據型別來建立物件
*/
public PersonInter getHair(String key) {
if ("student".equals(key)) {
return new StudentImpl();
} else if ("teacher".equals(key)) {
return new TeacherImpl();
}
return null;
}
/**
* 根據類的名稱來生產物件:java的對映
*/
public PersonInter getPersonByClassKey(String key) {
try {
Map<String, String> map = new PropertiesReader().getProperties();
PersonInter person = (PersonInter) Class.forName(map.get(key)).newInstance();
return person;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}