Android簡單的學生管理系統

(1)管理系統實現的功能主要是:學生、教師的註冊登錄,和選課,以及修改學生的成績等基本簡單的功能,最主要的是實現一些Dialog的使用。
界面如下:
這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述

這裡寫圖片描述

(2)主要代碼如下:(個人留作筆記,如需要完整代碼,在最下邊免費下載)

下邊是一個適配器,適配器是為瞭一個listvie進行設置值,其中加載的是一個itemview,適配器中還是用瞭繼承的方法,用於通知適配器進行更新。vcD4NCjxwcmUgY2xhc3M9″brush:java;”>
public class CourseAdapter extends BaseAdapter {

private Context context;
private List coursetList;

public CourseAdapter(Context context, List 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 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;
    }
}

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *