2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.widget.focus;
19 import android.app.ListActivity;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.AbsListView;
26 import android.widget.BaseAdapter;
27 import android.widget.Button;
28 import android.widget.TextView;
30 import com.google.android.collect.Lists;
31 import com.android.frameworks.coretests.R;
33 import java.util.List;
35 public class ListWithFooterViewAndNewLabels extends ListActivity {
37 private MyAdapter mMyAdapter;
40 protected void onCreate(Bundle icicle) {
41 super.onCreate(icicle);
43 setContentView(R.layout.list_with_button_above);
45 Button footerButton = new Button(this);
46 footerButton.setText("hi");
47 footerButton.setLayoutParams(
48 new AbsListView.LayoutParams(
49 ViewGroup.LayoutParams.WRAP_CONTENT,
50 ViewGroup.LayoutParams.WRAP_CONTENT));
51 getListView().addFooterView(footerButton);
53 mMyAdapter = new MyAdapter(this);
54 setListAdapter(mMyAdapter);
57 Button topButton = (Button) findViewById(R.id.button);
58 topButton.setText("click to add new item");
59 topButton.setOnClickListener(new View.OnClickListener() {
61 public void onClick(View v) {
62 mMyAdapter.addLabel("yo");
66 mMyAdapter.addLabel("first");
70 * An adapter that can take new string labels.
72 static class MyAdapter extends BaseAdapter {
74 private final Context mContext;
75 private List<String> mLabels = Lists.newArrayList();
77 public MyAdapter(Context context) {
81 public int getCount() {
82 return mLabels.size();
85 public Object getItem(int position) {
86 return mLabels.get(position);
89 public long getItemId(int position) {
93 public View getView(int position, View convertView, ViewGroup parent) {
94 String label = mLabels.get(position);
96 LayoutInflater inflater = (LayoutInflater)
97 mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
99 TextView tv = (TextView) inflater.inflate(
100 android.R.layout.simple_list_item_1,
106 public void addLabel(String s) {
107 mLabels.add(s + mLabels.size());
108 notifyDataSetChanged();