Android Open Source - Simple-Android-SQL-DB Example Activity






From Project

Back to project page Simple-Android-SQL-DB.

License

The source code is released under:

Apache License

If you think the Android project Simple-Android-SQL-DB 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 io.github.darkprayer93.example;
/*from   w ww. jav  a  2s  .  co m*/


import io.github.darkprayer93.database.SQLBasicRow;
import io.github.darkprayer93.database.SQLHelper;
import io.github.darkprayer93.simpleandroidsqldb.R;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class ExampleActivity extends FragmentActivity implements NoticeDialogFragment.NoticeDialogListener{

  public SQLHelper db = new SQLHelper(this);


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example);



    Button dialogButton = (Button) findViewById(R.id.open_dialog);


    try {
      dialogButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
          // TODO Auto-generated method stub
          try {
            showNoticeDialog();
          } catch (Exception ex) {
            Log.i("onClick showNoticeDialog ERROR", ex.toString());
          }
        }
      });
    }catch (Exception ex) {
      Log.i("onClick ERROR", ex.toString());
    }

    //        dialog.setOnClickListener(new View.OnClickListener() {
    //            public void onClick(View v) {
    //                m
    //            }
    //        });


    //        /**
    //         * CRUD Operations
    //         * */
    //        // add Books
    //        db.addSQLBasicRow(new SQLBasicRow("Android Application Development Cookbook", "Wei Meng Lee"));  
    //        db.addSQLBasicRow(new SQLBasicRow("Android Programming: The Big Nerd Ranch Guide", "Bill Phillips and Brian Hardy"));      
    //        db.addSQLBasicRow(new SQLBasicRow("Learn Android App Development", "Wallace Jackson"));
    // 
    //        // get all books
    //        List<SQLBasicRow> list = db.getAllSQLBasicRows();
    // 
    //        // delete one book
    //        db.deleteSQLBasicRow(list.get(0));
    // 
    //        // get all books
    //        db.getAllSQLBasicRows();

  }


  public void submit_data(String shortEditNAME, String shortEditURL ) {
    try{
      db.addSQLBasicRow(new SQLBasicRow(shortEditNAME , shortEditURL));
    } catch (Exception ex) {
      Log.i("Submit ERROR", ex.toString());
    }
  }


  public void showNoticeDialog() {
    // Create an instance of the dialog fragment and show it
    DialogFragment dialog = new NoticeDialogFragment();
    dialog.show(getSupportFragmentManager(), "NoticeDialogFragment");
  }

  // The dialog fragment receives a reference to this Activity through the
  // Fragment.onAttach() callback, which it uses to call the following methods
  // defined by the NoticeDialogFragment.NoticeDialogListener interface
  @Override
  public void onDialogPositiveClick(DialogFragment dialog) {
    // User touched the dialog's positive button

  }

  @Override
  public void onDialogNegativeClick(DialogFragment dialog) {
    // User touched the dialog's negative button

  }


}




Java Source Code List

io.github.darkprayer93.database.SQLBasicRow.java
io.github.darkprayer93.database.SQLHelper.java
io.github.darkprayer93.example.ExampleActivity.java
io.github.darkprayer93.example.NoticeDialogFragment.java