最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)之ListView的簡單用法及定制ListView界面操作示例

 更新時(shí)間:2019年04月03日 12:05:09   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)之ListView的簡單用法及定制ListView界面操作,結(jié)合實(shí)例形式分析了Android ListView界面布局相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)之ListView的簡單用法及定制ListView界面操作。分享給大家供大家參考,具體如下:

效果:

如何從獲得listview上item的內(nèi)容

詳見:http://m.fzitv.net/article/158000.htm

中遇到的問題部分。

布局實(shí)現(xiàn):

  • 有個(gè)listview顯示
  • 一個(gè)edit和button發(fā)送
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".MainActivity"
  android:orientation="vertical">
    <!--使用紅色得分割條-->
    <ListView
      android:id="@+id/list1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:divider="#f00"
      android:dividerHeight="2px"
      android:headerDividersEnabled="false">
    </ListView>
    <!--用于存放和發(fā)送新的信息-->
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:orientation="vertical"
      android:background="#ffffff">
        <!--存放新的信息-->
        <!--設(shè)置最大行數(shù)-->
        <EditText
          android:id="@+id/ifo"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:hint="請輸入內(nèi)容"
          android:textColorHint="#c0c0c0"
          android:maxLines="6"/>
        <!--點(diǎn)擊發(fā)送消息-->
        <Button
          android:id="@+id/send"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="發(fā)送"
          android:textSize="16sp" />
    </LinearLayout>
</RelativeLayout>

添加方法:

//此處由于只有String一條數(shù)據(jù),所以只用了ArrayAdapter
//如果多項(xiàng)信息建議用BaseAdapter
public class MainActivity extends AppCompatActivity {
  //當(dāng)前消息列表
  ListView list01 ;
  //消息發(fā)送欄
  EditText editText01 ;
  //消息發(fā)送按鈕
  Button button01_send ;
  //記錄數(shù)組長度
  int arr_num = 0;
  //定義一個(gè)數(shù)組
  String[] arr1 = new String[arr_num];
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    list01 = (ListView) findViewById(R.id.list1);
    editText01 = (EditText) findViewById(R.id.ifo);
    button01_send = (Button) findViewById(R.id.send);
    button01_send.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if ( ! editText01.getText().toString().equals("") ){
          String[] arr_new = new String[++arr_num];
//        System.arraycopy(arr1,0,arr_new,0, arr1.length);
          for (int j = 0 ; j < arr1.length; j++){
            arr_new[j] = arr1[j];
          }
          arr_new[arr_num-1] = editText01.getText().toString();
          arr1 = arr_new;
          ArrayAdapter adapter1;
          adapter1 = new ArrayAdapter<>(MainActivity.this,R.layout.array_list,arr_new);
          list01.setAdapter(adapter1);
          editText01.setText("");
        }else {
          Toast.makeText(MainActivity.this,"請輸入后再發(fā)送",Toast.LENGTH_SHORT).show();
        }
      }
    });
  }
}

帶圖片Demo:

Demo下載地址:點(diǎn)擊此處本站下載。

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》及《Android資源操作技巧匯總

希望本文所述對大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android使用viewpager實(shí)現(xiàn)畫廊式效果

    Android使用viewpager實(shí)現(xiàn)畫廊式效果

    這篇文章主要為大家詳細(xì)介紹了Android使用viewpager實(shí)現(xiàn)畫廊式效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • Android仿微信QQ設(shè)置圖形頭像裁剪功能

    Android仿微信QQ設(shè)置圖形頭像裁剪功能

    最近在做畢業(yè)設(shè)計(jì),想有一個(gè)功能和QQ一樣可以裁剪頭像并設(shè)置圓形頭像.圖片裁剪實(shí)現(xiàn)方式有兩種,一種是利用系統(tǒng)自帶的裁剪工具,一種是使用開源工具Cropper。本節(jié)就為大家?guī)砣绾问褂孟到y(tǒng)自帶的裁剪工具進(jìn)行圖片裁剪
    2016-10-10
  • Android中的HTextView庫實(shí)現(xiàn)TextView動(dòng)畫效果

    Android中的HTextView庫實(shí)現(xiàn)TextView動(dòng)畫效果

    HTextView是一個(gè)用來給TextView里的文字做各種轉(zhuǎn)換動(dòng)畫的開源庫,不僅提供了多種動(dòng)畫選擇,而且還有重復(fù)字符的位移動(dòng)畫,雖然并沒有多么復(fù)雜,但是它使用的這些典型的設(shè)計(jì)模式以及各種動(dòng)畫的實(shí)現(xiàn)確實(shí)可以從中讓我們學(xué)到不少知識
    2023-12-12
  • Android實(shí)現(xiàn)底部對話框BottomDialog彈出實(shí)例代碼

    Android實(shí)現(xiàn)底部對話框BottomDialog彈出實(shí)例代碼

    本篇文章主要介紹了Android實(shí)現(xiàn)底部對話框BottomDialog代碼。這里整理了詳細(xì)的代碼,有需要的小伙伴可以參考下。
    2017-03-03
  • 淺談Android手機(jī)聯(lián)系人開發(fā)之增刪查改功能

    淺談Android手機(jī)聯(lián)系人開發(fā)之增刪查改功能

    這篇文章主要介紹了Android手機(jī)聯(lián)系人開發(fā)之增刪查改功能,需要的朋友可以參考下
    2017-05-05
  • Android EditText實(shí)現(xiàn)分割輸入內(nèi)容

    Android EditText實(shí)現(xiàn)分割輸入內(nèi)容

    這篇文章主要為大家詳細(xì)介紹了Android EditText實(shí)現(xiàn)分割輸入內(nèi)容的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android自定義videoview仿抖音界面

    Android自定義videoview仿抖音界面

    這篇文章主要為大家詳細(xì)介紹了Android自定義videoview仿抖音界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android  View自定義鎖屏圖案

    Android View自定義鎖屏圖案

    這篇文章主要為大家詳細(xì)介紹了Android View自定義鎖屏圖案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Android開發(fā) 旋轉(zhuǎn)屏幕導(dǎo)致Activity重建解決方法

    Android開發(fā) 旋轉(zhuǎn)屏幕導(dǎo)致Activity重建解決方法

    Android開發(fā)文檔上專門有一小節(jié)解釋這個(gè)問題。簡單來說,Activity是負(fù)責(zé)與用戶交互的最主要機(jī)制,接下來為您詳細(xì)介紹
    2012-11-11
  • 一篇文章揭開Kotlin協(xié)程的神秘面紗

    一篇文章揭開Kotlin協(xié)程的神秘面紗

    最近看了下Kotlin的協(xié)程,覺得挺好的,寫篇文章總結(jié)總結(jié),所以下面這篇文章主要給大家介紹了關(guān)于Kotlin協(xié)程的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-08-08

最新評論

乡宁县| 桐城市| 木里| 邵阳市| 平安县| 新竹县| 定兴县| 江油市| 石棉县| 十堰市| 新余市| 建瓯市| 凤城市| 陈巴尔虎旗| 青冈县| 古交市| 惠水县| 临江市| 麟游县| 武穴市| 方正县| 镇原县| 卓尼县| 泰顺县| 玉门市| 达孜县| 方正县| 文昌市| 怀柔区| 莲花县| 珠海市| 石林| 金昌市| 大悟县| 嘉黎县| 松阳县| 威宁| 海阳市| 卢龙县| 清镇市| 同德县|