Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. package com.lvov.haim.notepad;
  2.  
  3. import android.content.Intent;
  4. import android.database.Cursor;
  5. import android.database.sqlite.SQLiteDatabase;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.Menu;
  9. import android.view.MenuItem;
  10. import android.widget.ArrayAdapter;
  11. import android.widget.ListView;
  12.  
  13. import java.util.ArrayList;
  14.  
  15. public class showData extends AppCompatActivity {
  16.     final boolean MAIN_ACTIVITY = false;
  17.  
  18.     ListView dataList;
  19.     ArrayList<String> userInfo;
  20.     ArrayAdapter<String> listAdapter;
  21.  
  22.     SQLiteDatabase sqldb;
  23.     DBHelper myDb;
  24.  
  25.     @Override
  26.     protected void onCreate(Bundle savedInstanceState) {
  27.         super.onCreate(savedInstanceState);
  28.         setContentView(R.layout.show_data);
  29.  
  30.         myDb = new DBHelper(this);
  31.  
  32.         dataList = findViewById(R.id.dataList);
  33.         userInfo = new ArrayList<>();
  34.         listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, userInfo);
  35.  
  36.         showDBInforomation();
  37.         dataList.setAdapter(listAdapter);
  38.     }
  39.  
  40.     @Override
  41.     public boolean onCreateOptionsMenu(Menu menu) {
  42.         // Inflate the menu; this adds items to the action bar if it is present.
  43.         getMenuInflater().inflate(R.menu.menu_main, menu);
  44.         return true;
  45.     }
  46.  
  47.     @Override
  48.     public boolean onOptionsItemSelected(MenuItem item) {
  49.         // Handle action bar item clicks here. The action bar will
  50.         // automatically handle clicks on the Home/Up button, so long
  51.         // as you specify a parent activity in AndroidManifest.xml.
  52.         int id = item.getItemId();
  53.  
  54.         //noinspection SimplifiableIfStatement
  55.         switch (id)
  56.         {
  57.             case R.id.menuTutorial:
  58.                 //Move to tutorial
  59.                 Intent credits = new Intent(this, Credits.class);
  60.                 startActivity(credits);
  61.             case R.id.menuCredits:
  62.                 //Move to credits
  63.                 Intent tutorial = new Intent(this, Tutorial.class);
  64.                 startActivity(tutorial);
  65.             case R.id.menuBack:
  66.                 if(MAIN_ACTIVITY)
  67.                 {
  68.                     return true;
  69.                 }
  70.                 else
  71.                 {
  72.                     finish();
  73.                 }
  74.         }
  75.  
  76.         return super.onOptionsItemSelected(item);
  77.     }
  78.  
  79.     public void showDBInforomation()
  80.     {
  81.         int colEmail, colName, colPhone;
  82.         String emailTemp = "", nameTemp = "", phoneTemp = "";
  83.         Cursor cursor;
  84.         String userDataGatherer = "";
  85.  
  86.         sqldb = myDb.getWritableDatabase();
  87.         cursor = sqldb.query(DBHelper.TABLE_NAME, null, null, null, null, null, null);
  88.  
  89.         colEmail = cursor.getColumnIndex(DBHelper.EMAIL);
  90.         colName = cursor.getColumnIndex(DBHelper.PHONE);
  91.         colPhone = cursor.getColumnIndex(DBHelper.PASSWORD);
  92.  
  93.         cursor.moveToFirst();
  94.  
  95.         while(!cursor.isAfterLast())
  96.         {
  97.             emailTemp = cursor.getString(colEmail);
  98.             nameTemp = cursor.getString(colName);
  99.             phoneTemp = cursor.getString(colPhone);
  100.  
  101.             userDataGatherer = "Name: " + nameTemp +
  102.                                "\nPhone: " + phoneTemp +
  103.                                "\nEmail: " + emailTemp;
  104.  
  105.             userInfo.add(userDataGatherer);
  106.  
  107.             cursor.moveToNext();
  108.         }
  109.  
  110.         cursor.close();
  111.         sqldb.close();
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement