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