1 /* 2 * Copyright (C) 2010 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 com.example.android.apis.view; 18 19 import android.app.ListActivity; 20 import android.os.Bundle; 21 import android.view.View; 22 import android.widget.ArrayAdapter; 23 import android.widget.ListView; 24 25 26 /** 27 * A list view where the last item the user clicked is placed in 28 * the "activated" state, causing its background to highlight. 29 */ 30 public class List17 extends ListActivity { 31 32 @Override 33 public void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 36 // Use the built-in layout for showing a list item with a single 37 // line of text whose background is changes when activated. 38 setListAdapter(new ArrayAdapter<String>(this, 39 android.R.layout.simple_list_item_activated_1, mStrings)); 40 getListView().setTextFilterEnabled(true); 41 42 // Tell the list view to show one checked/activated item at a time. 43 getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); 44 45 // Start with first item activated. 46 // Make the newly clicked item the currently selected one. 47 getListView().setItemChecked(0, true); 48 } 49 50 @Override 51 protected void onListItemClick(ListView l, View v, int position, long id) { 52 // Make the newly clicked item the currently selected one. 53 getListView().setItemChecked(position, true); 54 } 55 56 private String[] mStrings = Cheeses.sCheeseStrings; 57 } 58