亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android用戶輸入自動提示控件AutoCompleteTextView使用方法

 更新時間:2017年08月07日 14:15:46   作者:飯飯_fan  
這篇文章主要為大家詳細介紹了Android用戶輸入自動提示控件AutoCompleteTextView的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

一、簡介

1、AutoCompleteTextView的作用

 

2、AutoCompleteTextView的類結構圖

也就是擁有EditText的各種功能 

3、AutoCompleteTextView工作原理

AutoCompleteTextView的自動提示功能肯定需要適配器提供數據

4、Android里的適配器

5、適合AutoCompleteTextView的適配器

ArrayAdapter

二、AutoCompleteTextView實現自動提示的方法

 1)AutoCompleteTextView實現自動提示的方法

第一步、創(chuàng)建適配器

String[] arr={"凱撒","凱撒廣場","凱撒大帝"};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.textview, arr);

第二步、AutoCompleteTextView對象應用適配器

autoCompleteTextView1.setAdapter(adapter);

說明:

提示文本是用textview實現的,提示文本里面的提示數據就是String[] arr。

三、代碼實例

代碼:

fry.Activity01

package fry;

import com.example.AutoCompleteTextViewDemo1.R;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class Activity01 extends Activity{
 private AutoCompleteTextView autoCompleteTextView1;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity01);
  autoCompleteTextView1=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
  /*
   * AutoCompleteTextView實現自動提示的方法
   * 第一步、創(chuàng)建適配器
   * 第二步、AutoCompleteTextView對象應用適配器
   * 
   */
  
  String[] arr={"凱撒","凱撒廣場","凱撒大帝"};
  ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.textview, arr);
  autoCompleteTextView1.setAdapter(adapter);
 }
}

fry.Activity01

<?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" >

 <AutoCompleteTextView 
  android:id="@+id/autoCompleteTextView1"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  />

</LinearLayout>

/AutoCompleteTextViewDemo1/res/layout/textview.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >
 <!-- 這里是直接TextView,而不是layout下的TextView -->
</TextView > 

四、易錯點

1、這里是直接TextView,而不是layout下的TextView

/AutoCompleteTextViewDemo1/res/layout/textview.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical" >
 <!-- 這里是直接TextView,而不是layout下的TextView -->
</TextView >

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Android 如何使用SQLite保存數據

    Android 如何使用SQLite保存數據

    對于重復數據或結構化數據(例如聯(lián)系信息),將數據保存到數據庫是理想選擇,SQL 數據庫的主要原則之一是架構,即數據庫組織方式的正式聲明,本篇文章介紹在 Android 上使用 SQLite 數據庫,感興趣的朋友一起看看吧
    2024-03-03
  • Android中SharedPreferences簡單使用實例

    Android中SharedPreferences簡單使用實例

    這篇文章主要介紹了Android中SharedPreferences簡單使用案例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Flutter框架實現Android拖動到垃圾桶刪除效果

    Flutter框架實現Android拖動到垃圾桶刪除效果

    這篇文章主要介紹了Flutter框架實現Android拖動到垃圾桶刪除效果,Flutter框架中的Draggable部件,用于支持用戶通過手勢拖動,它是基于手勢的一種方式,可以使用戶可以在屏幕上拖動指定的部件,下面我們來詳細了解一下
    2023-12-12
  • android自定義View圓圈拖動

    android自定義View圓圈拖動

    這篇文章主要為大家詳細介紹了android自定義View圓圈拖動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • Android手機聯(lián)系人快速索引(手機通訊錄)

    Android手機聯(lián)系人快速索引(手機通訊錄)

    最近需要實現一個手機通訊錄的快速索引功能。根據姓名首字母快速索引功能,下面通過本篇文章給大家介紹Android手機聯(lián)系人快速索引(手機通訊錄)的相關代碼,需要的朋友參考下
    2015-12-12
  • android簡單自定義View實現五子棋

    android簡單自定義View實現五子棋

    這篇文章主要為大家詳細介紹了android簡單自定義View實現五子棋,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android實現紙飛機的簡單操作

    Android實現紙飛機的簡單操作

    這篇文章主要為大家詳細介紹了Android實現紙飛機的簡單操作,類似于漂流瓶功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android實現炫酷的CheckBox效果

    Android實現炫酷的CheckBox效果

    大家是不是對系統(tǒng)自帶的CheckBox產生乏味感了呢?今天這篇文章給大家?guī)淼氖且豢钊碌腃heckBox,下面來一起看看下面的CheckBox吧!有需要的朋友們可以參考借鑒。
    2016-10-10
  • Android 自定義SeekBar動態(tài)改變硬件音量大小實現和音量鍵的同步(推薦)

    Android 自定義SeekBar動態(tài)改變硬件音量大小實現和音量鍵的同步(推薦)

    這篇文章主要介紹了 Android 自定義SeekBar動態(tài)改變硬件音量大小實現和音量鍵的同步效果,整段代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-01-01
  • Android TextView字體顏色設置方法小結

    Android TextView字體顏色設置方法小結

    這篇文章主要介紹了Android TextView字體顏色設置方法,結合實例形式總結分析了Android開發(fā)中TextView設置字體顏色的常用技巧,需要的朋友可以參考下
    2016-02-02

最新評論