Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package com.example.administrator.myapplication;
  2.  
  3.  
  4. import android.database.Cursor;
  5. import android.os.Bundle;
  6. import android.support.annotation.Nullable;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.util.Log;
  9.  
  10. import android.widget.ArrayAdapter;
  11. import android.widget.ListAdapter;
  12. import android.widget.ListView;
  13. import android.widget.Toast;
  14.  
  15. import java.util.ArrayList;
  16.  
  17.  
  18. /**
  19. * Created by b00717051 on 27/04/2018.
  20. */
  21.  
  22. public class ListDataActivity extends AppCompatActivity {
  23. private static final String TAG = "ListDataActivity";
  24.  
  25. DatabaseHelper mDatabaseHelper;
  26.  
  27. private ListView mListView;
  28.  
  29. @Override
  30. protected void onCreate(@Nullable Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.list_layout);
  33. mListView = (ListView) findViewById(R.id.listView);
  34. mDatabaseHelper = new DatabaseHelper(this);
  35.  
  36. populateListView();
  37. }
  38.  
  39. private void populateListView() {
  40. Log.d(TAG, "populateListView: Displaying data in the ListView.");
  41.  
  42. //get the data and append to a list
  43. Cursor data = mDatabaseHelper.getData();
  44. ArrayList<String> listData = new ArrayList<>();
  45. while (data.moveToNext()) {
  46. //get the value from the database in column 1
  47. //then add it to the ArrayList
  48. listData.add(data.getString(1) + " Sit Ups");
  49. }
  50. ListAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, listData);
  51. mListView.setAdapter(adapter);
  52. }
  53. private void toastMessage(String message){
  54. Toast.makeText(this,message, Toast.LENGTH_SHORT).show();
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement