Guest User

Untitled

a guest
Feb 25th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | None | 0 0
  1. package com.example.marci.parserv1;
  2.  
  3. import android.database.Cursor;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.support.v7.widget.Toolbar;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.widget.TextView;
  10.  
  11. public class University extends AppCompatActivity {
  12.  
  13.     private TextView textView;
  14.     protected static final String TAG = "University";
  15.     public void ShowAllBtn(View v){
  16.         takeOne();
  17.     }
  18.     public void ShowRandomBtn(View v){
  19.         takeRandom();
  20.     }
  21.     @Override
  22.     protected void onCreate(Bundle savedInstanceState) {
  23.         super.onCreate(savedInstanceState);
  24.         setContentView(R.layout.activity_university);
  25.         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  26.         setSupportActionBar(toolbar);
  27.         textView = (TextView) findViewById(R.id.textView);
  28.  
  29.  
  30.        TestAdapter mDbHelper = new TestAdapter(this);
  31.         mDbHelper.createDatabase();
  32.         mDbHelper.open();
  33.         Log.d(TAG, "Stworzyłem DB");
  34.         mDbHelper.close();
  35.  
  36.         }
  37.     private void takeRandom() {
  38.  
  39.         TestAdapter mDbHelper = new TestAdapter(this);
  40.         mDbHelper.createDatabase();
  41.         mDbHelper.open();
  42.         Cursor testdata = mDbHelper.getTestData();
  43.  
  44.  
  45.         while (testdata.moveToNext()) {
  46.             String nazwa = testdata.getString(1);
  47.             String wydzial = testdata.getString(2);
  48.             String adres = testdata.getString(3);
  49.             textView.setText(nazwa + wydzial + adres);
  50.         }
  51.         mDbHelper.close();
  52.     }
  53.  
  54.  
  55.     private void takeOne(){
  56.         TestAdapter mDbHelper = new TestAdapter(this);
  57.         mDbHelper.createDatabase();
  58.         mDbHelper.open();
  59.         String taskName = textView.getText().toString();
  60.         Cursor testdata = mDbHelper.getResult(taskName);
  61.  
  62.             String nazwa = testdata.getString(1);
  63.             String wydział = testdata.getString(2);
  64.             String adres = testdata.getString(3);
  65.             Log.d(TAG, "Pobrano wszystkie wiersze i przypisano do zmiennych");
  66.  
  67.             textView.setText(textView.getText() + "\n" + nazwa + "\n" + wydział + "\n" + adres);
  68.             Log.d(TAG, "Pobrano wszystkie wiersze przypisano do zmiennych I dodano do textView");
  69.             mDbHelper.close();
  70.     }
  71.     private void takeAll() {
  72.  
  73.         TestAdapter mDbHelper = new TestAdapter(this);
  74.         mDbHelper.createDatabase();
  75.         mDbHelper.open();
  76.  
  77.         Cursor testdata = mDbHelper.getAll();
  78.  
  79.         while(testdata.moveToNext()) {
  80.             int nr = testdata.getInt(0);
  81.             String nazwa = testdata.getString(1);
  82.             String wydział = testdata.getString(2);
  83.             String adres = testdata.getString(3);
  84.             Log.d(TAG, "Pobrano wszystkie wiersze i przypisano do zmiennych");
  85.  
  86.             textView.setText(textView.getText() + "\n" + nazwa + "\n" + wydział + "\n" + adres);
  87.             Log.d(TAG, "Pobrano wszystkie wiersze przypisano do zmiennych I dodano do textView");
  88.             mDbHelper.close();
  89.         }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.     }
  98.  
  99. }
Add Comment
Please, Sign In to add comment