Android Open Source - Attendance-AutoCounter Class Activity

From Project

Back to project page Attendance-AutoCounter.


The source code is released under:

GNU General Public License

If you think the Android project Attendance-AutoCounter 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

package com.etonn.attendance_autocounter;
//from  w w  w. j  a  v a 2s . co  m
import android.content.ContentValues;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import com.etonn.attendance_autocounter.db.DBManager;

import java.util.ArrayList;

public class ClassActivity extends ActionBarActivity {

    ListView listViewClass; // for Class name listview
    DBManager db;

    protected void onCreate(Bundle savedInstanceState) {

        // init database
        db = new DBManager(ClassActivity.this);

        // add listener
        listViewClass.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                CourseModifyDialog mDialog = new CourseModifyDialog();
      , "dialogCourse");

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == {
            return true;

        return super.onOptionsItemSelected(item);

     * show Classes list
    private void showClassList() {
        // get new data from db
        ArrayList al = db.getClassList();
        // update list
        listViewClass = (ListView) findViewById(;
        // bind listview with ArrayAdapter
        listViewClass.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, al));

     * add class into db
     * @param view
    public void addClass(View view) {
        // get Class name
        EditText editTextClassName = (EditText) findViewById(;
        String className = editTextClassName.getText().toString();
        EditText editTextHeadcount = (EditText) findViewById(;
        String headcount = editTextHeadcount.getText().toString();
        if (className.isEmpty() || headcount.isEmpty()) {
            Toast.makeText(getApplicationContext(), "Please fill in Class name and Headcount.", Toast.LENGTH_SHORT).show();
        } else {
            // save to DB
            ContentValues contentValues = new ContentValues();
            contentValues.put("class_name", className);
            contentValues.put("headcount", Integer.parseInt(headcount));

            // show Classes list

            // empty EditText



Java Source Code List