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.listview; 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.view.LayoutInflater; 27 import android.widget.BaseAdapter; 28 import android.widget.TextView; 29 30 /** 31 * Exercises moving focus into the list from the side 32 */ 33 public class ListTakeFocusFromSide extends ListActivity { 34 35 36 private class ThrashListAdapter extends BaseAdapter { 37 private LayoutInflater mInflater; 38 39 private String[] mTitles = new String[100]; 40 ThrashListAdapter(Context context)41 public ThrashListAdapter(Context context) { 42 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 43 mTitles = new String[100]; 44 45 int i; 46 for (i = 0; i < 100; i++) { 47 mTitles[i] = "[" + i + "]"; 48 } 49 } 50 getCount()51 public int getCount() { 52 return mTitles.length; 53 } 54 getItem(int position)55 public Object getItem(int position) { 56 return position; 57 } 58 getItemId(int position)59 public long getItemId(int position) { 60 return position; 61 } 62 getView(int position, View convertView, ViewGroup parent)63 public View getView(int position, View convertView, ViewGroup parent) { 64 TextView view; 65 66 if (convertView == null) { 67 view = (TextView) mInflater.inflate(android.R.layout.simple_list_item_1, null); 68 } else { 69 view = (TextView) convertView; 70 } 71 view.setText(mTitles[position]); 72 return view; 73 } 74 75 } 76 77 @Override onCreate(Bundle icicle)78 public void onCreate(Bundle icicle) { 79 super.onCreate(icicle); 80 81 setContentView(R.layout.list_take_focus_from_side); 82 setListAdapter(new ThrashListAdapter(this)); 83 } 84 } 85