1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.widget.focus; 18 19 import com.android.frameworks.coretests.R; 20 21 import android.app.ListActivity; 22 import android.content.Context; 23 import android.os.Bundle; 24 import android.view.View; 25 import android.view.ViewGroup; 26 import android.widget.ArrayAdapter; 27 import android.widget.Button; 28 29 /** 30 * A layout with a ListView containing buttons. 31 */ 32 public class ListOfButtons extends ListActivity { 33 34 35 @Override 36 protected void onCreate(Bundle icicle) { 37 super.onCreate(icicle); 38 39 setContentView(R.layout.list_with_button_above); 40 getListView().setItemsCanFocus(true); 41 setListAdapter(new MyAdapter(this, mLabels)); 42 } 43 44 String[] mLabels = { 45 "Alabama", "Alaska", "Arizona", "apple sauce!", 46 "California", "Colorado", "Connecticut", "Delaware" 47 }; 48 49 50 public String[] getLabels() { 51 return mLabels; 52 } 53 54 public static class MyAdapter extends ArrayAdapter<String> { 55 56 57 public MyAdapter(Context context, String[] labels) { 58 super(context, 0, labels); 59 } 60 61 62 @Override 63 public View getView(int position, View convertView, ViewGroup parent) { 64 String label = getItem(position); 65 66 Button button = new Button(parent.getContext()); 67 button.setText(label); 68 return button; 69 } 70 71 @Override 72 public boolean areAllItemsEnabled() { 73 return false; 74 } 75 } 76 } 77