egslava

List Activity

Jun 24th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. package ru.egslava.telemed.ui.druglist;
  2.  
  3. import android.database.Cursor;
  4. //import android.support.v4.content.CursorLoader;
  5. import android.support.v4.app.FragmentActivity;
  6. import android.widget.AbsListView;
  7. import android.widget.ListView;
  8.  
  9. import ru.egslava.telemed.R;
  10. import ru.egslava.telemed.model.DrugContract;
  11. import ru.egslava.telemed.ui.utils.content.ContentListAdapter;
  12. import ru.egslava.telemed.ui.utils.content.ContentListLoader;
  13.  
  14. import org.androidannotations.annotations.AfterViews;
  15. import org.androidannotations.annotations.Bean;
  16. import org.androidannotations.annotations.EActivity;
  17. import org.androidannotations.annotations.ItemClick;
  18. import org.androidannotations.annotations.ViewById;
  19.  
  20. /**
  21.  * Created by egslava on 01/05/15.
  22.  */
  23.  
  24. @EActivity(R.layout.activity_drug_list)
  25. public class DrugListActivity extends FragmentActivity { // instead of just Activity for SupportLoader
  26.  
  27.     @ViewById   ListView list;
  28.  
  29.     public  ContentListAdapter adapter;
  30.     @Bean   ContentListLoader contentListLoader;
  31.  
  32.     @AfterViews void init() {
  33.         list.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
  34.  
  35.         adapter = new ContentListAdapter<>(this, list, SelectableDrugItem_::build);
  36.         list.setAdapter(adapter);
  37.         contentListLoader.init( getSupportLoaderManager(), DrugContract.CONTENT_URI, adapter );
  38.     }
  39.  
  40.     @ItemClick void list ( Cursor cursor ) {
  41.         // I fixed that bug too much time. In the beginning ListView will call setChecked with
  42.         // its own (ListView) values. You can change it with ListView.setItemChecked
  43.         // (see listParams.setItemChecked( position, drug.inCart ) in DrugItem.bind );
  44.  
  45.         // So if you will notify right from Checkable.setChecked it will change cursor and
  46.         // in the new beginning will call setChecked again and again cursor will be changed
  47.         getContentResolver().notifyChange(DrugContract.CONTENT_URI, null);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment