欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

效果:

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

詳見:http://www.dbjr.com.cn/article/158000.htm

中遇到的問(wèn)題部分。

布局實(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="請(qǐng)輸入內(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ù)組長(zhǎng)度
  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,"請(qǐng)輸入后再發(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ù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總

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

相關(guān)文章

  • Android百度地圖應(yīng)用之MapFragment的使用

    Android百度地圖應(yīng)用之MapFragment的使用

    這篇文章主要為大家詳細(xì)介紹了Android百度地圖應(yīng)用之MapFragment的使用的相關(guān)資料,需要的朋友可以參考下
    2016-06-06
  • Android上傳多張圖片的實(shí)例代碼(RxJava異步分發(fā))

    Android上傳多張圖片的實(shí)例代碼(RxJava異步分發(fā))

    本篇文章主要介紹了Android上傳多張圖片的實(shí)例代碼(RxJava異步分發(fā)),具有一定的參考價(jià)值,有興趣的可以了解一下
    2017-08-08
  • Android中Edittext設(shè)置輸入條件

    Android中Edittext設(shè)置輸入條件

    本篇文章主要介紹了Android中Edittext設(shè)置輸入條件的相關(guān)知識(shí),具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧
    2017-05-05
  • android之listview懸浮topBar效果

    android之listview懸浮topBar效果

    這篇文章主要為大家詳細(xì)介紹了android之listview懸浮topBar效果的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android打開圖庫(kù)選擇照片功能代碼

    Android打開圖庫(kù)選擇照片功能代碼

    這篇文章主要介紹了Android打開圖庫(kù)選擇照片功能代碼以及實(shí)現(xiàn)流程分析,對(duì)此有需要的朋友參考學(xué)習(xí)下吧。
    2018-02-02
  • Android AOP注解Annotation詳解(一)

    Android AOP注解Annotation詳解(一)

    這篇文章主要介紹了Android AOP注解Annotation詳細(xì)介紹的相關(guān)資料,Annotation是代碼里的特殊標(biāo)記,這些標(biāo)記可以在編譯、類加載、運(yùn)行時(shí)被讀取,并執(zhí)行相應(yīng)的處理,需要的朋友可以參考下
    2017-03-03
  • android仿iphone滾輪控件顯示效果

    android仿iphone滾輪控件顯示效果

    這篇文章主要為大家詳細(xì)介紹了android仿iphone滾輪控件顯示效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Android獲取手機(jī)聯(lián)系人電話號(hào)碼并返回結(jié)果

    Android獲取手機(jī)聯(lián)系人電話號(hào)碼并返回結(jié)果

    這篇文章主要為大家詳細(xì)介紹了Android獲取手機(jī)聯(lián)系人電話號(hào)碼并返回結(jié)果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • AndroidStduio3.0 使用gradle將module打包jar文件的方法

    AndroidStduio3.0 使用gradle將module打包jar文件的方法

    這篇文章主要介紹了AndroidStduio3.0 使用gradle將module打包jar文件的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-04-04
  • 淺談Android Studio 3.0 的一些小變化

    淺談Android Studio 3.0 的一些小變化

    本篇文章主要介紹了淺談Android Studio 3.0 的一些小變化,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10

最新評(píng)論