mardi 12 janvier 2016

View SQLite data with ViewPage

I am trying to use a ViewPage to display some data like names of student from SQLite. It works well when I display the information on a listview. Now I want to view each student record in a ViewPage where a page only contains one student record. I fetched the information form the SQLite and put it in a list but I was unable to display it in the ViewPage.

Here is my OnCreateView Method:

public View OnCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState)  
     View rootView=inflater.inflate(R.layout.fragment_main, container, false);
    TextView textView=(TextView) rootView.findViewById(R.id.section_Label);

   //I used the code bellow to display the data on listView which worked fine
   //textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER));

  // I now try to the the following to display it on ViewPage
  List<String> quotes=databaseAccess.getQuotes//I the getQuotes class is bellow

  textView.setText(quotes);//I assume this suppose to put each of the list element in the PageView

My getQuotes Class is :

public List<String> getQuotes()  {
     List<String> list=new ArrayList<>();
     Cursor cursor= database.rawQuery("SELECT * FROM quotes", null;
     cursor.moveToFirst();
     while (!cursor.isAfterLast()) {
           list.add(cursor.getString(0));
           cursor.moveToNext();
     }
     cursor.close();
     return list;
   }
   }

Please I need help. I'm doing it in the wrong way or I need to adjust something. Thank you in advance

Aucun commentaire:

Enregistrer un commentaire