FileDocCategorySizeDatePackage
ListWithEmptyView.javaAPI DocAndroid 5.1 API3153Thu Mar 12 22:22:12 GMT 2015android.widget.listview

ListWithEmptyView

public class ListWithEmptyView extends android.app.ListActivity
Tests using an empty view with a list

Fields Summary
public static final int
MENU_ADD
public static final int
MENU_REMOVE
private CarefulAdapter
mAdapter
private int
mNextItem
private android.view.View
mEmptyView
Constructors Summary
Methods Summary
public android.view.ViewgetEmptyView()

        return mEmptyView;
    
public voidonCreate(android.os.Bundle savedInstanceState)

    
    
        
        super.onCreate(savedInstanceState);
        mAdapter = new CarefulAdapter<String>(this,
                android.R.layout.simple_list_item_1);
        setContentView(R.layout.list_with_empty_view);
        setListAdapter(mAdapter);
        
        mEmptyView = findViewById(R.id.empty);
        getListView().setEmptyView(mEmptyView);
    
public booleanonCreateOptionsMenu(android.view.Menu menu)

        super.onCreateOptionsMenu(menu);
        menu.add(0, MENU_ADD, 0, R.string.menu_add)
                .setIcon(android.R.drawable.ic_menu_add);
        menu.add(0, MENU_REMOVE, 0, R.string.menu_remove)
                .setIcon(android.R.drawable.ic_menu_delete);
        return true;
    
public booleanonOptionsItemSelected(android.view.MenuItem item)

        switch (item.getItemId()) {
            case MENU_ADD:
                String str = "Item + " + mNextItem++;
                mAdapter.add(str);
                return true;
            case MENU_REMOVE:
                if (mAdapter.getCount() > 0) {
                    mAdapter.remove(mAdapter.getItem(0));
                }
                return true;
        }

        return super.onOptionsItemSelected(item);