| /* | |
| * Copyright 2013 The Android Open Source Project | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| package com.example.android.customchoicelist; | |
| import android.app.ListActivity; | |
| import android.os.Bundle; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.widget.BaseAdapter; | |
| import android.widget.TextView; | |
| /** | |
| * This sample demonstrates how to create custom single- or multi-choice | |
| * {@link android.widget.ListView} UIs. The most interesting bits are in | |
| * the <code>res/layout/</code> directory of this sample. | |
| */ | |
| public class MainActivity extends ListActivity { | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.sample_main); | |
| setListAdapter(new MyAdapter()); | |
| } | |
| /** | |
| * A simple array adapter that creates a list of cheeses. | |
| */ | |
| private class MyAdapter extends BaseAdapter { | |
| @Override | |
| public int getCount() { | |
| return Cheeses.CHEESES.length; | |
| } | |
| @Override | |
| public String getItem(int position) { | |
| return Cheeses.CHEESES[position]; | |
| } | |
| @Override | |
| public long getItemId(int position) { | |
| return Cheeses.CHEESES[position].hashCode(); | |
| } | |
| @Override | |
| public View getView(int position, View convertView, ViewGroup container) { | |
| if (convertView == null) { | |
| convertView = getLayoutInflater().inflate(R.layout.list_item, container, false); | |
| } | |
| ((TextView) convertView.findViewById(android.R.id.text1)) | |
| .setText(getItem(position)); | |
| return convertView; | |
| } | |
| } | |
| } |