Android:listview automatically generate list entries

Source: Internet
Author: User

The Activity_list.xml file code is as follows:
1<?xml version="1.0"encoding="Utf-8"?>2<LinearLayout3Xmlns:android="http://schemas.android.com/apk/res/android"4android:orientation="Vertical"5Android:layout_width="fill_parent"6android:layout_height="fill_parent">7 8<ListView9Android:id="@+id/listview"TenAndroid:layout_width="match_parent" Oneandroid:layout_height="match_parent"> A</ListView> -  -</LinearLayout>
The Listactivity.java file code is as follows:
1 Package Com.example.sample_6_4;2 3 ImportAndroid.app.Dialog;4 ImportAndroid.graphics.Color;5 Importandroid.preference.DialogPreference;6 ImportAndroid.support.v7.app.AlertDialog;7 Importandroid.support.v7.app.AppCompatActivity;8 ImportAndroid.os.Bundle;9 ImportAndroid.view.View;Ten ImportAndroid.view.ViewGroup; One ImportAndroid.view.WindowManager; A ImportAndroid.widget.ArrayAdapter; - ImportAndroid.widget.BaseAdapter; - ImportAndroid.widget.Button; the ImportAndroid.widget.ListView; - ImportAndroid.widget.TextView; -  -PublicclassListactivity extends Appcompatactivity { + @Override - protected void OnCreate (Bundle savedinstancestate) { + super.oncreate (savedinstancestate); A Setcontentview (r.layout.activity_list); atListView LV =(ListView) Findviewbyid (R.id.listview); -//make an adapter to use the ListView - Lv.setadapter (New Myadapter ()); -     } -     classMyadapter extends baseadapter{ - @Override in//returns the number of entries, the list of entries, such as how many bars a screen displays - public int GetCount () { to             return20; +         } - @Override the//determine the layout and content of each entry, position represents the location of the entry, starting with 0 * Public View GetView (int position, View Converview, ViewGroup parent) { $TextView TV =new TextView (listactivity.this);Panax NotoginsengTv.settext ("Articles"+position); -Tv.settextsize (23); the Tv.settextcolor (color.blue); +             returnTV; A         } the @Override + Public Object GetItem (int position) { -             returnnull; $         } $ @Override - Public long Getitemid (int position) { -             return0; the         } -     }Wuyi}
The effect is as follows:

Android:listview automatically generate list entries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.