<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Android 列表視圖示例 > 原文: [https://javatutorial.net/android-list-view-example](https://javatutorial.net/android-list-view-example) 您已經學習了 Android 的許多其他布局,本教程通過示例說明了 android 中的列表視圖。 ## `ListView` 您要在應用中顯示列表嗎? Android 通過提供列表視圖布局來解決其問題。 它是一種布局,在垂直可滾動列表中顯示項目。 列表中的每個項目都位于列表中上一個項目的下方。 列表項存儲在數組中,并由[使用適配器](https://javatutorial.net/android-listview-with-listadapter-example)從列表中拉出項目,然后將其插入列表。 列表視圖是`AdapterView`的子類。 自定義列表在移動應用程序中非常常見,列表視圖提供了一種創建自定義列表的簡便方法。 它是最常用的布局之一,例如,當您要顯示一組日期時,沒有什么比列表更合適的了。 下圖顯示了列表視圖的外觀 ![list view](https://img.kancloud.cn/38/4b/384b6b489da6fb5f309b7b0442e10362_300x275.jpg) 列表顯示 ## 列表視圖的屬性 這是列表視圖的一些重要 XML 屬性。 `android: divider`,它用作繪制能力或顏色,用于在列表項之間繪制。 `android: entries`,它用于引用數組資源以填充列表視圖。 `android: headerDividersEnabled`,用于在每個標題視圖之后繪制分隔線。 `android: footerDividersEanabled`,用于在每個頁腳視圖之前繪制分隔線。 ## 列表視圖的方法 列表視圖有許多公共方法,下面將對其中的一些方法進行說明。 * `getAdapter()`:返回列表視圖中使用的適配器。 * `addHeaderView()`:用于在列表頂部添加標題視圖。 * `getAccessibilityClassName()`:返回對象的類名。 * `getDivider()`:返回列表中每個項目之間的分隔符。 * `getDividerHeight()`:返回分隔線的高度。 * `isOpaque()`:顯示列表是否不透明。 * `removeFooterView(View view)`:用于刪除列表中先前添加的頁腳視圖。 * `removeHeaderView(View view)`:用于刪除列表中先前添加的標題視圖。 ## 列表視圖的構造函數 列表視圖具有四個不同的公共構造函數,如下所示: * `ListView(Context context)` * `ListView(Context context, AttributeSet attrs)` * `ListView(Context context, AttributeSet attrs, int defStyleAttr)` * `ListView(Context context, AttributeSet attrs, AttributeSet attrs, int defStyleRes)` ## 列表視圖的示例 這是在 Android 中使用列表視圖的示例。 它顯示了計算機科學中的語言列表。 首先創建一個活動,打開活動`_main.xml`并粘貼此代碼 ```java <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/mobile_list" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout> ``` 創建另一個布局作為`activity_listview.xml`并粘貼此代碼 ```java <?xml version="1.0" encoding="utf-8"?> <!-- Single List Item Design --> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dip" android:textSize="16dip" android:textStyle="bold" > </TextView> ``` 打開您的 MainActivity.java 并使用此代碼 ```java package com.example.admin.listviewexample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends AppCompatActivity { String[] mobileArray = {"Java","C++","C#","CSS", "HTML","XML",".Net","VisualBasic", "SQL", "Python", "PHP"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, mobileArray); ListView listView = (ListView) findViewById(R.id.mobile_list); listView.setAdapter(adapter); } } ``` 這是輸出的樣子 ![list view example](https://img.kancloud.cn/75/19/751981f661df6631fa279d82ccfc31b5_371x655.jpg) 列表視圖示例 您可以通過以下[鏈接](https://github.com/JavaTutorialNetwork/Tutorials/blob/master/ListViewExample.rar)下載此示例代碼。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看