Android ListView自動(dòng)生成列表?xiàng)l目的實(shí)例
activity_list.xml文件代碼如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> </LinearLayout>
ListActivity.java文件代碼如下:
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); //做一個(gè)適配器來(lái)使用ListView lv.setAdapter(new MyAdapter()); } class MyAdapter extends BaseAdapter{ @Override //返回條目的個(gè)數(shù),列表的條目,例如一個(gè)屏幕顯示多少條 public int getCount(){ return 20; } @Override //確定每個(gè)條目的布局和內(nèi)容,position代表?xiàng)l目的位置,從0開(kāi)始 public View getView(int position, View converView, ViewGroup parent){ TextView tv = new TextView(ListActivity.this); tv.setText("條目" + 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; } } }
以上這篇Android ListView自動(dòng)生成列表?xiàng)l目的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Android RecyclerView實(shí)現(xiàn)點(diǎn)擊條目刪除
- Android自定義SwipeLayout仿QQ側(cè)滑條目
- Android仿京東分類模塊左側(cè)分類條目效果
- Android更多條目收縮展開(kāi)控件ExpandView的示例代碼
- Android XRecyclerView實(shí)現(xiàn)多條目加載
- Android條目拖拽刪除功能實(shí)例代碼
- Android ListView 條目多樣式展示實(shí)例詳解
- android RecyclerView實(shí)現(xiàn)條目Item拖拽排序與滑動(dòng)刪除
- Android中l(wèi)istview和imageview實(shí)現(xiàn)條目單選效果
- Android編程實(shí)現(xiàn)canvas繪制餅狀統(tǒng)計(jì)圖功能示例【自動(dòng)適應(yīng)條目數(shù)量與大小】
- Android中RecyclerView上拉下拉,分割線,多條目的實(shí)例代碼
- Android 中 SwipeLayout一個(gè)展示條目底層菜單的側(cè)滑控件源碼解析
- 詳解Android中實(shí)現(xiàn)ListView左右滑動(dòng)刪除條目的方法
- Android實(shí)現(xiàn)下拉展示條目效果
相關(guān)文章
Android?RecyclerView使用ListAdapter高效刷新數(shù)據(jù)的操作方法
這篇文章主要介紹了Android?RecyclerView使用ListAdapter高效刷新數(shù)據(jù),本次也是介紹了用另外一種方法來(lái)實(shí)現(xiàn)RecyclerView高效刷新數(shù)據(jù)的功能,需要的朋友可以參考下2022-10-10安卓(Android)中如何實(shí)現(xiàn)滑動(dòng)導(dǎo)航
導(dǎo)航是移動(dòng)應(yīng)用最重要的方面之一,對(duì)用戶體驗(yàn)是良好還是糟糕起著至關(guān)重要的作用。好的導(dǎo)航可以讓一款應(yīng)用更加易用并且讓用戶快速上手。相反,糟糕的應(yīng)用導(dǎo)航很容易讓人討厭,并遭到用戶的拋棄。2014-08-08Android 網(wǎng)絡(luò)圖片查看器與網(wǎng)頁(yè)源碼查看器
本篇文章主要介紹了Android 網(wǎng)絡(luò)圖片查看器與網(wǎng)頁(yè)源碼查看器的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04Android實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫的兩種方式案例詳解
這篇文章主要介紹了Android實(shí)現(xiàn)旋轉(zhuǎn)動(dòng)畫的兩種方式,需要的朋友可以參考下2021-08-08Android?無(wú)障礙服務(wù)?performAction?調(diào)用過(guò)程分析
這篇文章主要介紹了Android?無(wú)障礙服務(wù)?performAction?調(diào)用過(guò)程分析,無(wú)障礙服務(wù)可以模擬一些用戶操作,無(wú)障礙可以處理的對(duì)象,通過(guò)類?AccessibilityNodeInfo?表示,通過(guò)無(wú)障礙服務(wù),可以通過(guò)它的performAction方法來(lái)觸發(fā)一些action2022-06-06老生常談ProgressBar、ProgessDialog的用法
下面小編就為大家?guī)?lái)一篇老生常談ProgressBar、ProgessDialog的用法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07Mac OS下為Android Studio編譯FFmpeg解碼庫(kù)的詳細(xì)教程
這篇文章主要介紹了Mac OS下為Android Studio編譯FFmpeg解碼庫(kù)的詳細(xì)教程,包括NDK的配置和Android Studio的配置兩個(gè)部分的內(nèi)容,需要的朋友可以參考下2016-01-01Android入門之計(jì)時(shí)器Chronometer的使用教程
Chronometer是一個(gè)簡(jiǎn)單的定時(shí)器,你可以給它一個(gè)開(kāi)始時(shí)間,并以此定時(shí)。本文將利用個(gè)簡(jiǎn)單的示例為大家講解一下它的使用,感興趣的小伙伴可以嘗試一下2022-11-11Android指紋識(shí)別功能深入淺出分析到實(shí)戰(zhàn)(6.0以下系統(tǒng)解決方案)
指紋識(shí)別在現(xiàn)實(shí)應(yīng)用中已經(jīng)很多了,本篇文章主要介紹了Android指紋識(shí)別功能,具有一定的參考價(jià)值,有需要的可以了解一下。2016-11-11