Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.bronx.englishforfun;
- import android.content.Context;
- import android.content.Intent;
- import android.database.Cursor;
- import android.support.v7.app.ActionBarActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ListView;
- import android.widget.TextView;
- public class listawyrazow extends ActionBarActivity {
- protected static final String TAG = "slowko";
- private ListView lv_slowa;
- DataBaseAdapter myDb;
- private TextView text3;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_listawyrazow);
- lv_slowa = (ListView)findViewById(R.id.lv_slowa);
- //populateListViewFromDB();
- DataBaseAdapter mDbHelper = new DataBaseAdapter(this);
- mDbHelper.createDatabase();
- mDbHelper.open();
- Log.d(TAG, "Stworzyłem DB");
- takeAll();
- mDbHelper.close();
- lv_slowa.setClickable(true);
- lv_slowa.setOnClickListener(new AdapterView.OnItemClickListener(){
- public void onItemClick(AdapterView<?> arg0, View arg2, int position, long arg3) {
- Intent intent = new Intent(listawyrazow.this, slowo.class);
- String link = testdata.get(position).getString();
- intent.putExtra(FILTER, link);
- startActivity(intent);
- }
- });
- }
- private void openDB() {
- myDb = new DataBaseAdapter(this);
- myDb.open();
- }
- private void closeDB() {
- myDb.close();
- }
- @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_listawyrazow, 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
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- public void takeAll() {
- DataBaseAdapter mDbHelper = new DataBaseAdapter(this);
- mDbHelper.createDatabase();
- mDbHelper.open();
- ListView lvItems = (ListView) findViewById(R.id.lv_slowa);
- text3 = (TextView) findViewById(R.id.text3);
- Cursor testdata = mDbHelper.getAll();
- if (testdata != null && testdata.moveToFirst()) {
- do {
- TodoAdapter todoAdapter = new TodoAdapter(this, testdata);
- lvItems.setAdapter(todoAdapter);
- //mDbHelper.close();
- } while (testdata.moveToNext());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment