K
K
kolodach2014-04-04 20:42:12
Java
kolodach, 2014-04-04 20:42:12

Empty list view andriod - why?

The program uses an activity like "fixed tabs + swipe". One of the fragments contains a list view, which should connect to the sqlite database. Since my experience is not enough, I tried to describe the connection to the database directly in the "OnCreateView ()" method in the fragment class.
Alas, to no avail. Then I tried to put it into a separate method - the same thing, I get an empty list view. The database is not empty. Fragment class code:

public static class DummySectionFragment extends Fragment implements LoaderCallbacks<Cursor>{

    public static final String ARG_SECTION_NUMBER = "section_number";
    public DummySectionFragment() {
    }
    View v;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.activity_tracker,
          container, false);
      v = inflater.inflate(R.layout.activity_tracker,
          container, false);
      createList();

      return rootView;
    }

    public void createList(){
      db = new DB(act);
      db.open();
      String[] from = new String[] {DB.COLUMN_NAME, DB.COLUMN_TIME};
      int[] to = new int[] { R.id.tvTextName, R.id.tvText_time};
      
      Cursor cursor = db.getAllData();
      
      scAdapter = new SimpleCursorAdapter(getActivity(), R.layout.item, cursor, from, to, 0);
      lvData = (ListView) v.findViewById(R.id.lvData);
      lvData.setAdapter(scAdapter);
    }

    @Override
    public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
      // TODO Auto-generated method stub
      
    }

    @Override
    public void onLoaderReset(Loader<Cursor> arg0) {
      // TODO Auto-generated method stub
      
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey M, 2014-04-16
@Collosteam

Try
inserting after the line

if(cursor != null)
Log.d("DummySectionFragment ", "count : "+cursor.getCount());

And see what will be displayed in the log, because the filled database does not mean that everything should work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question