Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate list entries automatically by Android ListView

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "Android ListView how to automatically generate list entries", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Android ListView how to automatically generate list entries" article.

The activity_list.xml file code is as follows:

The ListActivity.java file code is as follows:

Package com.example.sample_6_4;import android.app.Dialog;import android.graphics.Color;import android.preference.DialogPreference;import android.support.v7.app.AlertDialog;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.view.WindowManager;import android.widget.ArrayAdapter;import android.widget.BaseAdapter;import android.widget.Button;import android.widget.ListView;import android.widget.TextView Public class ListActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_list); ListView lv = (ListView) findViewById (R.id.listview); / / make an adapter to use ListView lv.setAdapter (new MyAdapter ());} class MyAdapter extends BaseAdapter {@ Override / / returns the number of entries, list entries, such as how many public int getCount () {return 20 is displayed on a screen } @ Override / / determine the layout and content of each entry. Position represents the location of each entry. Starting from 0, public View getView (int position, View converView, ViewGroup parent) {TextView tv = new TextView (ListActivity.this); tv.setText ("entry" + position); tv.setTextSize (23); tv.setTextColor (Color.BLUE); return tv;} @ Override public Object getItem (int position) {return null;} @ Override public long getItemId (int position) {return 0 } the above is about the content of this article on "how to automatically generate list entries in Android ListView". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report