Add buttons to a listactivity

前端 未结 1 1848
感动是毒
感动是毒 2020-12-14 11:11

I have a layout for a ListActivity. To modify the list I have used menu-options. But to remove a couple of \"clicks\" on the screen I\'d like to add two buttons in the butto

1条回答
  •  悲&欢浪女
    2020-12-14 11:43

    From http://developer.android.com/reference/android/app/ListActivity.html:

    “ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list"”

    EDIT: here is an example:

    The ListActivity may be created like this:

    public class ListViewTest extends ListActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            String[] values = {"One", "Two", "Three"};
    
            setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, values));
    
            setContentView(R.layout.main);
        }
    }
    

    The main.xml layout is as follows:

    
    
    
        android:id="@android:id/list">
        
    
    

    0 讨论(0)
提交回复
热议问题