Get the App
SLTechnology News&Howtos  ›  Development  › 

How to generate list entries automatically by Android ListView

Shulou Source: shulou.com Published: 2022-05-31 21:28:45 09月10日 Update

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.

Tags: Items content automatic generation generation code files articles knowledge articles number representation value location reply slips most of them that is screens layouts more to make Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Huawei macOS Shulou Technology Apple