1 /*
2  * Copyright (C) 2017 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.supportv7.widget;
18 
19 import android.os.Bundle;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.BaseAdapter;
24 import android.widget.ListView;
25 import android.widget.TextView;
26 
27 import androidx.appcompat.app.AppCompatActivity;
28 
29 import com.example.android.supportv7.R;
30 
31 /**
32  * Sample activity for the demo of list item styles.
33  */
34 public class ListViewActivity extends AppCompatActivity {
35     @Override
onCreate(Bundle savedInstanceState)36     protected void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38 
39         setContentView(R.layout.list_view_activity);
40         ListView listView = findViewById(R.id.list_view);
41         listView.setAdapter(new BaseAdapter() {
42             @Override
43             public int getCount() {
44                 return 100;
45             }
46 
47             @Override
48             public Object getItem(int i) {
49                 return null;
50             }
51 
52             @Override
53             public long getItemId(int i) {
54                 return i;
55             }
56 
57             @Override
58             public View getView(int i, View view, ViewGroup viewGroup) {
59                 // this is just a demo, so not using view holders
60                 if (view == null) {
61                     view = LayoutInflater.from(viewGroup.getContext()).inflate(
62                             R.layout.list_view_item, viewGroup, false);
63                 }
64                 TextView title = (TextView) view.findViewById(R.id.title);
65                 TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
66                 title.setText("Title for #" + i);
67                 subtitle.setText("Subtitle for #" + i);
68                 return view;
69             }
70         });
71     }
72 }
73