2011-04-13 2 views
0

J'ai déjà utilisé le code suivant pour afficher la liste des éléments favoris. Il a une fonctionnalité de suppression via le menu contextuel.android SimpleCursorAdapter no item msg

@Override 
    public void onCreate(Bundle savedInstanceState) { 

    ......................... 
    ......................... 

     wordDataHelper = new WordDataHelper(getApplicationContext()); 
     favCursor = wordDataHelper.getCursorFav(); 
     startManagingCursor(favCursor); 
     // Now create a new list adapter bound to the cursor. 
     // SimpleListAdapter is designed for binding to a Cursor. 
     favAdapter = new SimpleCursorAdapter(
       this, // Context. 
       android.R.layout.simple_list_item_1, 
       favCursor,            // Pass in the cursor to bind to. 
       new String[] {WordDataHelper.ENGWORD},   // Array of cursor columns to bind to. 
       new int[] {android.R.id.text1}); // Parallel array of which template objects to bind to those columns. 

     // Bind to our new adapter. 
     setListAdapter(favAdapter); 

     list = getListView(); 


list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { 
      // @Override 
      public void onCreateContextMenu(ContextMenu menu, View v, 
        ContextMenu.ContextMenuInfo menuInfo) { 
       menu.setHeaderTitle("Context Menu"); 
       menu.add(0, CONTEXT_DELETE, 1, "Delete Item"); 
      } 
     }); 

     list.setTextFilterEnabled(true); 

     list.setClickable(true); 

     .................. 
    .................. 
} 

public boolean onContextItemSelected(MenuItem item) { 

     AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item 
       .getMenuInfo(); 
     final Long wordId = menuInfo.id; 
     // selected_row = menuInfo.position; 

     // To get the id of the clicked item in the list use menuInfo.id 
     switch (item.getItemId()) { 
     case CONTEXT_DELETE: 
      deleteRes(wordId); 
      favCursor = wordDataHelper.getCursorFav(); 
      ((SimpleCursorAdapter) favAdapter).changeCursor(favCursor); 
      break; 
     default: 
      return super.onContextItemSelected(item); 

     } 


     return true; 
    } 

Tout fonctionne correctement. Maintenant, je veux afficher un msg "Aucun élément favori" lorsqu'il n'y a aucun élément à lister. Comment l'organiser?

Répondre

0
+0

J'ai ajouté la liste = getListView(); Voir empty = (Voir) findViewById (R.layout.empty); list.setEmptyView (vide); où Mais rien n'apparaît. Quel est le problème? –

Questions connexes