Guest User

Untitled

a guest
Mar 7th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. package com.example.bronx.englishforfun;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.database.Cursor;
  6. import android.support.v7.app.ActionBarActivity;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.Menu;
  10. import android.view.MenuItem;
  11. import android.view.View;
  12. import android.widget.AdapterView;
  13. import android.widget.ListView;
  14. import android.widget.TextView;
  15.  
  16.  
  17. public class listawyrazow extends ActionBarActivity {
  18.  
  19. protected static final String TAG = "slowko";
  20. private ListView lv_slowa;
  21. DataBaseAdapter myDb;
  22. private TextView text3;
  23.  
  24.  
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_listawyrazow);
  29. lv_slowa = (ListView)findViewById(R.id.lv_slowa);
  30. //populateListViewFromDB();
  31.  
  32.  
  33. DataBaseAdapter mDbHelper = new DataBaseAdapter(this);
  34. mDbHelper.createDatabase();
  35. mDbHelper.open();
  36. Log.d(TAG, "Stworzyłem DB");
  37. takeAll();
  38. mDbHelper.close();
  39.  
  40. lv_slowa.setClickable(true);
  41. lv_slowa.setOnClickListener(new AdapterView.OnItemClickListener(){
  42. public void onItemClick(AdapterView<?> arg0, View arg2, int position, long arg3) {
  43. Intent intent = new Intent(listawyrazow.this, slowo.class);
  44. String link = testdata.get(position).getString();
  45. intent.putExtra(FILTER, link);
  46.  
  47. startActivity(intent);
  48. }
  49.  
  50. });
  51. }
  52.  
  53. private void openDB() {
  54. myDb = new DataBaseAdapter(this);
  55. myDb.open();
  56. }
  57. private void closeDB() {
  58. myDb.close();
  59. }
  60.  
  61.  
  62.  
  63. @Override
  64. public boolean onCreateOptionsMenu(Menu menu) {
  65. // Inflate the menu; this adds items to the action bar if it is present.
  66. getMenuInflater().inflate(R.menu.menu_listawyrazow, menu);
  67. return true;
  68. }
  69.  
  70. @Override
  71. public boolean onOptionsItemSelected(MenuItem item) {
  72. // Handle action bar item clicks here. The action bar will
  73. // automatically handle clicks on the Home/Up button, so long
  74. // as you specify a parent activity in AndroidManifest.xml.
  75. int id = item.getItemId();
  76.  
  77. //noinspection SimplifiableIfStatement
  78. if (id == R.id.action_settings) {
  79. return true;
  80. }
  81.  
  82. return super.onOptionsItemSelected(item);
  83. }
  84. public void takeAll() {
  85. DataBaseAdapter mDbHelper = new DataBaseAdapter(this);
  86. mDbHelper.createDatabase();
  87. mDbHelper.open();
  88.  
  89. ListView lvItems = (ListView) findViewById(R.id.lv_slowa);
  90. text3 = (TextView) findViewById(R.id.text3);
  91.  
  92.  
  93. Cursor testdata = mDbHelper.getAll();
  94. if (testdata != null && testdata.moveToFirst()) {
  95. do {
  96. TodoAdapter todoAdapter = new TodoAdapter(this, testdata);
  97. lvItems.setAdapter(todoAdapter);
  98.  
  99.  
  100. //mDbHelper.close();
  101. } while (testdata.moveToNext());
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment