Skip to main content

Posts

Showing posts with the label cursoradapter

Best practices to query SQLite database in ListFragment with CursorLoader?

I'm using Android Compatibility Library in my project. I've set up ListFragment as described in the DevGuide ( http://developer.android.com/reference/android/app/Fragment.html ), and using a simple CursorLoader Christian made be used without content provider ( Usage CursorLoader without ContentProvider ). The question is where, in my ListFragment / parent Activity, should I open database, return the Cursor, create Adapter and setListAdapter? So in my app, I have TitlesFragment, DetailsFragment, FragmentLayoutActivity, DetailsLayoutActivity. Is the best practice... to open database in ListFragment's onActivityCreated and close it in ListFragment's onDestroy like in code sample below @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Open database playersDatabaseHelper = new PlayersDBAdapter(getActivity()); playersDatabaseHelper.open(); getLoaderManager()

Getting the Selected View from ListView

I am using a CursorAdapter to handle my ListActivity: public class Mclass extends ListActivity{ ... TheAdapter mAdapter; public static HashMap<Long, Boolean> shown = new HashMap<Long, Boolean>(); ... @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Boolean tmp = shown.get(id); if (tmp == null) { // if null we don't have this key in the hashmap so we added with the value true shown.put(id, true); } else { shown.put(id, !tmp.booleanValue()); // if the value exists in the map then inverse it's value } mAdapter.notifyDataSetChanged(); } } And my adapter class extends CursorAdapter and overrides bindView @Override public void bindView(View view, Context context, Cursor cursor) { String listText= cursor .getString(cursor .getColumnIndexOrThrow(DataHandler.MY_TEXT)); long id = curs

Getting the Selected View from ListView

I am using a CursorAdapter to handle my ListActivity: public class Mclass extends ListActivity{ ... TheAdapter mAdapter; public static HashMap<Long, Boolean> shown = new HashMap<Long, Boolean>(); ... @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Boolean tmp = shown.get(id); if (tmp == null) { // if null we don't have this key in the hashmap so we added with the value true shown.put(id, true); } else { shown.put(id, !tmp.booleanValue()); // if the value exists in the map then inverse it's value } mAdapter.notifyDataSetChanged(); } } And my adapter class extends CursorAdapter and overrides bindView @Override public void bindView(View view, Context context, Cursor cursor) { String listText= cursor .getString(cursor .getColumnIndexOrThrow(DataHandler.MY_TEXT)); long id = curs