Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.marci.parserv1;
- import android.database.Cursor;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.util.Log;
- import android.view.View;
- import android.widget.TextView;
- public class University extends AppCompatActivity {
- private TextView textView;
- protected static final String TAG = "University";
- public void ShowAllBtn(View v){
- takeOne();
- }
- public void ShowRandomBtn(View v){
- takeRandom();
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_university);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- textView = (TextView) findViewById(R.id.textView);
- TestAdapter mDbHelper = new TestAdapter(this);
- mDbHelper.createDatabase();
- mDbHelper.open();
- Log.d(TAG, "Stworzyłem DB");
- mDbHelper.close();
- }
- private void takeRandom() {
- TestAdapter mDbHelper = new TestAdapter(this);
- mDbHelper.createDatabase();
- mDbHelper.open();
- Cursor testdata = mDbHelper.getTestData();
- while (testdata.moveToNext()) {
- String nazwa = testdata.getString(1);
- String wydzial = testdata.getString(2);
- String adres = testdata.getString(3);
- textView.setText(nazwa + wydzial + adres);
- }
- mDbHelper.close();
- }
- private void takeOne(){
- TestAdapter mDbHelper = new TestAdapter(this);
- mDbHelper.createDatabase();
- mDbHelper.open();
- String taskName = textView.getText().toString();
- Cursor testdata = mDbHelper.getResult(taskName);
- String nazwa = testdata.getString(1);
- String wydział = testdata.getString(2);
- String adres = testdata.getString(3);
- Log.d(TAG, "Pobrano wszystkie wiersze i przypisano do zmiennych");
- textView.setText(textView.getText() + "\n" + nazwa + "\n" + wydział + "\n" + adres);
- Log.d(TAG, "Pobrano wszystkie wiersze przypisano do zmiennych I dodano do textView");
- mDbHelper.close();
- }
- private void takeAll() {
- TestAdapter mDbHelper = new TestAdapter(this);
- mDbHelper.createDatabase();
- mDbHelper.open();
- Cursor testdata = mDbHelper.getAll();
- while(testdata.moveToNext()) {
- int nr = testdata.getInt(0);
- String nazwa = testdata.getString(1);
- String wydział = testdata.getString(2);
- String adres = testdata.getString(3);
- Log.d(TAG, "Pobrano wszystkie wiersze i przypisano do zmiennych");
- textView.setText(textView.getText() + "\n" + nazwa + "\n" + wydział + "\n" + adres);
- Log.d(TAG, "Pobrano wszystkie wiersze przypisano do zmiennych I dodano do textView");
- mDbHelper.close();
- }
- }
- }
Add Comment
Please, Sign In to add comment