listView无需适配器添加数据(写demo快速开发)entries属性的特殊用法
生活随笔
收集整理的這篇文章主要介紹了
listView无需适配器添加数据(写demo快速开发)entries属性的特殊用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先看下簡單的布局代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:padding="10dp"><Buttonandroid:id="@+id/bt"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="20dp"android:text="按鈕" /><ImageViewandroid:id="@+id/iv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="20dp"android:src="@mipmap/ic_launcher" /><EditTextandroid:id="@+id/et"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="20dp"android:hint="請輸入文本" /><ProgressBarandroid:id="@+id/pb"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_margin="20dp"android:background="@color/colorAccent" /><ListViewandroid:id="@+id/tv"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="20dp"android:entries="@array/datas" /></LinearLayout>
<resources><string name="app_name">JavaToKotlin</string><string-array name="data"><item>1</item><item>2</item><item>3</item><item>4</item><item>5</item><item>6</item><item>7</item><item>8</item><item>9</item><item>10</item></string-array> </resources>
再來看下,主要代碼
再來看下entries這個數據怎么寫:
當然根據我的發現,這個數據目前可以有兩種寫法
寫法一:.可以寫在String.xml文件中:如下
<resources><string name="app_name">JavaToKotlin</string><string-array name="data"><item>1</item><item>2</item><item>3</item><item>4</item><item>5</item><item>6</item><item>7</item><item>8</item><item>9</item><item>10</item></string-array> </resources>
看不懂得可看截圖:
寫法二:
可以單獨定義一個arrays.xml效果是一樣的如下:
同樣看不懂得可看截圖:
大家再來看下,這個entries屬性的效果圖,是否跟用適配器開發的效果一樣:
說白了這個entries屬性就相當于一個簡單的數組,可以存放簡單的數據,方便開發
需要源碼的點擊下載源碼listView無需適配器添加數據(寫demo快速開發)entries屬性的特殊用法
總結
以上是生活随笔為你收集整理的listView无需适配器添加数据(写demo快速开发)entries属性的特殊用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用flash简单绘制一个漂亮的桃心(教学
- 下一篇: 通过adb命令查看当前activity(