Android Open Source - Android-ORM Student Grade Detail Activity






From Project

Back to project page Android-ORM.

License

The source code is released under:

Apache License

If you think the Android project Android-ORM listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * // w  w  w . j a  v a 2s. c  o m
 */
package cn.ieclipse.aorm.example;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import cn.ieclipse.aorm.example.bean.Course;
import cn.ieclipse.aorm.example.bean.Grade;
import cn.ieclipse.aorm.example.bean.Student;

/**
 * @author Jamling
 * 
 */
public class StudentGradeDetailActivity extends DetailActivity {
    
    private Student student;
    private Grade grade;
    private EditText etName;
    private Spinner spnCourse;
    private EditText etScore;
    private List<Course> courseList;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        etIndex = (EditText) findViewById(R.id.et_no);
        etName = (EditText) findViewById(R.id.et_name);
        etScore = (EditText) findViewById(R.id.et_score);
        spnCourse = (Spinner) findViewById(R.id.spn_course);
        session = ExampleContentProvider.getSession();
        courseList = session.list(Course.class);
        spnCourse.setAdapter(new CourseAdapter(this, courseList));
        
        if (student != null) {
            etName.setText(student.getName());
        }
        
        grade = session.get(Grade.class, id);
        if (grade != null) {
            int i = 0;
            for (Course c : courseList) {
                if (c.getId() == grade.getCid()) {
                    spnCourse.setSelection(i);
                    break;
                }
                i++;
            }
            etScore.setText(String.valueOf(grade.getScore()));
            
            student = (Student) session.get(Student.class, grade.getSid());
            etName.setText(student.getName());
        }
    }
    
    @Override
    protected void initIntent(Intent intent, Bundle savedInstanceState) {
        super.initIntent(intent, savedInstanceState);
        long sid = intent.getLongExtra("sid", 0);
        if (sid > 0) {
            student = ExampleContentProvider.getSession().get(Student.class,
                    sid);
        }
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see cn.ieclipse.aorm.example.DetailActivity#getLayout()
     */
    @Override
    protected int getLayout() {
        return R.layout.student_grade_detail;
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see cn.ieclipse.aorm.example.DetailActivity#delete()
     */
    @Override
    protected boolean delete() {
        int count = session.deleteById(Grade.class, id);
        return count > 0;
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see cn.ieclipse.aorm.example.DetailActivity#edit()
     */
    @Override
    protected boolean edit() {
        if (grade != null) {
            Course c = (Course) spnCourse.getSelectedItem();
            grade.setCid(c.getId());
            float score = 0f;
            try {
                score = Float.valueOf(etScore.getText().toString());
            } catch (Exception e) {
                
            }
            grade.setScore(score);
            int count = session.update(grade);
            return count > 0;
        }
        return false;
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see cn.ieclipse.aorm.example.DetailActivity#save()
     */
    @Override
    protected boolean save() {
        Grade grade = new Grade();
        Course c = (Course) spnCourse.getSelectedItem();
        grade.setCid(c.getId());
        float score = 0f;
        try {
            score = Float.valueOf(etScore.getText().toString());
        } catch (Exception e) {
            
        }
        grade.setScore(score);
        grade.setSid(student.getId());
        id = session.insert(grade);
        if (id > 0) {
            this.grade = grade;
        }
        return id > 0;
    }
    
    private static class CourseAdapter extends AbstractBaseAdapter<Course> {
        
        public CourseAdapter(Context context, List<Course> dataList) {
            super(context, dataList);
        }
        
        @Override
        protected int getLayout() {
            return android.R.layout.simple_dropdown_item_1line;
        }
        
        @Override
        protected void onUpdateView(View view, int position) {
            Course s = getItem(position);
            TextView tvName = (TextView) view.findViewById(android.R.id.text1);
            tvName.setText(s.getName());
        }
        
    }
}




Java Source Code List

android.content.ContentResolver.java
android.content.ContentValues.java
android.database.ContentObserver.java
android.database.Cursor.java
android.database.sqlite.SQLiteDatabase.java
android.database.sqlite.SQLiteOpenHelper.java
android.net.Uri.java
android.os.Handler.java
android.util.FastPrintWriter.java
android.util.Log.java
android.util.Printer.java
cn.ieclipse.aorm.Aorm.java
cn.ieclipse.aorm.Criteria.java
cn.ieclipse.aorm.CursorUtils.java
cn.ieclipse.aorm.Mapping.java
cn.ieclipse.aorm.ORMException.java
cn.ieclipse.aorm.Order.java
cn.ieclipse.aorm.Restrictions.java
cn.ieclipse.aorm.SessionObserver.java
cn.ieclipse.aorm.Session.java
cn.ieclipse.aorm.annotation.ColumnWrap.java
cn.ieclipse.aorm.annotation.Column.java
cn.ieclipse.aorm.annotation.TableWrap.java
cn.ieclipse.aorm.annotation.Table.java
cn.ieclipse.aorm.example.AbstractBaseAdapter.java
cn.ieclipse.aorm.example.BaseActivity.java
cn.ieclipse.aorm.example.CourseDetailActivity.java
cn.ieclipse.aorm.example.CourseListActivity.java
cn.ieclipse.aorm.example.DetailActivity.java
cn.ieclipse.aorm.example.ExampleApplication.java
cn.ieclipse.aorm.example.ExampleContentProvider.java
cn.ieclipse.aorm.example.ListActivity.java
cn.ieclipse.aorm.example.MainActivity.java
cn.ieclipse.aorm.example.StudentDetailActivity.java
cn.ieclipse.aorm.example.StudentGradeActivity.java
cn.ieclipse.aorm.example.StudentGradeDetailActivity.java
cn.ieclipse.aorm.example.StudentListActivity.java
cn.ieclipse.aorm.example.bean.Course.java
cn.ieclipse.aorm.example.bean.Grade.java
cn.ieclipse.aorm.example.bean.Student.java