| /* |
| * Copyright (C) 2017 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.supportv7.widget; |
| |
| import android.os.Bundle; |
| import android.support.v7.app.AppCompatActivity; |
| import android.view.LayoutInflater; |
| import android.view.View; |
| import android.view.ViewGroup; |
| import android.widget.BaseAdapter; |
| import android.widget.ListView; |
| import android.widget.TextView; |
| |
| import com.example.android.supportv7.R; |
| |
| /** |
| * Sample activity for the demo of list item styles. |
| */ |
| public class ListViewActivity extends AppCompatActivity { |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| |
| setContentView(R.layout.list_view_activity); |
| ListView listView = findViewById(R.id.list_view); |
| listView.setAdapter(new BaseAdapter() { |
| @Override |
| public int getCount() { |
| return 100; |
| } |
| |
| @Override |
| public Object getItem(int i) { |
| return null; |
| } |
| |
| @Override |
| public long getItemId(int i) { |
| return i; |
| } |
| |
| @Override |
| public View getView(int i, View view, ViewGroup viewGroup) { |
| // this is just a demo, so not using view holders |
| if (view == null) { |
| view = LayoutInflater.from(viewGroup.getContext()).inflate( |
| R.layout.list_view_item, viewGroup, false); |
| } |
| TextView title = (TextView) view.findViewById(R.id.title); |
| TextView subtitle = (TextView) view.findViewById(R.id.subtitle); |
| title.setText("Title for #" + i); |
| subtitle.setText("Subtitle for #" + i); |
| return view; |
| } |
| }); |
| } |
| } |