Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lvov.haim.notepad;
- import android.content.Intent;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- import java.util.ArrayList;
- public class showData extends AppCompatActivity {
- final boolean MAIN_ACTIVITY = false;
- ListView dataList;
- ArrayList<String> userInfo;
- ArrayAdapter<String> listAdapter;
- SQLiteDatabase sqldb;
- DBHelper myDb;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.show_data);
- myDb = new DBHelper(this);
- dataList = findViewById(R.id.dataList);
- userInfo = new ArrayList<>();
- listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, userInfo);
- showDBInforomation();
- dataList.setAdapter(listAdapter);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- 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
- switch (id)
- {
- case R.id.menuTutorial:
- //Move to tutorial
- Intent credits = new Intent(this, Credits.class);
- startActivity(credits);
- case R.id.menuCredits:
- //Move to credits
- Intent tutorial = new Intent(this, Tutorial.class);
- startActivity(tutorial);
- case R.id.menuBack:
- if(MAIN_ACTIVITY)
- {
- return true;
- }
- else
- {
- finish();
- }
- }
- return super.onOptionsItemSelected(item);
- }
- public void showDBInforomation()
- {
- int colEmail, colName, colPhone;
- String emailTemp = "", nameTemp = "", phoneTemp = "";
- Cursor cursor;
- String userDataGatherer = "";
- sqldb = myDb.getWritableDatabase();
- cursor = sqldb.query(DBHelper.TABLE_NAME, null, null, null, null, null, null);
- colEmail = cursor.getColumnIndex(DBHelper.EMAIL);
- colName = cursor.getColumnIndex(DBHelper.PHONE);
- colPhone = cursor.getColumnIndex(DBHelper.PASSWORD);
- cursor.moveToFirst();
- while(!cursor.isAfterLast())
- {
- emailTemp = cursor.getString(colEmail);
- nameTemp = cursor.getString(colName);
- phoneTemp = cursor.getString(colPhone);
- userDataGatherer = "Name: " + nameTemp +
- "\nPhone: " + phoneTemp +
- "\nEmail: " + emailTemp;
- userInfo.add(userDataGatherer);
- cursor.moveToNext();
- }
- cursor.close();
- sqldb.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement