Home | History | Annotate | Download | only in view
      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 com.example.android.apis.view;
     18 
     19 // Need the following import to get access to the app resources, since this
     20 // class is in a sub-package.
     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 /**
     32  * A list view example with separators.
     33  */
     34 public class List5 extends ListActivity {
     35 
     36     @Override
     37     public void onCreate(Bundle savedInstanceState) {
     38         super.onCreate(savedInstanceState);
     39 
     40         setListAdapter(new MyListAdapter(this));
     41     }
     42 
     43     private class MyListAdapter extends BaseAdapter {
     44         public MyListAdapter(Context context) {
     45             mContext = context;
     46         }
     47 
     48         public int getCount() {
     49             return mStrings.length;
     50         }
     51 
     52         @Override
     53         public boolean areAllItemsEnabled() {
     54             return false;
     55         }
     56 
     57         @Override
     58         public boolean isEnabled(int position) {
     59             return !mStrings[position].startsWith("-");
     60         }
     61 
     62         public Object getItem(int position) {
     63             return position;
     64         }
     65 
     66         public long getItemId(int position) {
     67             return position;
     68         }
     69 
     70         public View getView(int position, View convertView, ViewGroup parent) {
     71             TextView tv;
     72             if (convertView == null) {
     73                 tv = (TextView) LayoutInflater.from(mContext).inflate(
     74                         android.R.layout.simple_expandable_list_item_1, parent, false);
     75             } else {
     76                 tv = (TextView) convertView;
     77             }
     78             tv.setText(mStrings[position]);
     79             return tv;
     80         }
     81 
     82         private Context mContext;
     83     }
     84 
     85     private String[] mStrings = {
     86             "----------",
     87             "----------",
     88             "Abbaye de Belloc",
     89             "Abbaye du Mont des Cats",
     90             "Abertam",
     91             "----------",
     92             "Abondance",
     93             "----------",
     94             "Ackawi",
     95             "Acorn",
     96             "Adelost",
     97             "Affidelice au Chablis",
     98             "Afuega'l Pitu",
     99             "Airag",
    100             "----------",
    101             "Airedale",
    102             "Aisy Cendre",
    103             "----------",
    104             "Allgauer Emmentaler",
    105             "Alverca",
    106             "Ambert",
    107             "American Cheese",
    108             "Ami du Chambertin",
    109             "----------",
    110             "----------",
    111             "Anejo Enchilado",
    112             "Anneau du Vic-Bilh",
    113             "Anthoriro",
    114             "----------",
    115             "----------"
    116     };
    117 
    118 }
    119