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

Android流式布局實(shí)現(xiàn)歷史搜索記錄功能

 更新時(shí)間:2017年05月09日 11:12:11   作者:zhang_li_yong  
最近在開(kāi)發(fā)項(xiàng)目的時(shí)候,有一個(gè)需求是展示歷史搜索記錄 ,展示的樣式是流式布局(就是根據(jù)內(nèi)容自動(dòng)換行)。接下來(lái)通過(guò)本文給大家分享android流式布局實(shí)現(xiàn)歷史搜索記錄功能,感興趣的的小伙伴參考下

最近在開(kāi)發(fā)項(xiàng)目的時(shí)候,有一個(gè)需求是展示歷史搜索記錄 ,展示的樣式是流式布局(就是根據(jù)內(nèi)容自動(dòng)換行)。在網(wǎng)上看到了一個(gè)不錯(cuò)的類庫(kù)跟大家分享一下

首先在AndroidStudio簡(jiǎn)歷一個(gè)工程項(xiàng)目導(dǎo)入module類庫(kù),我會(huì)把項(xiàng)目demo方法GitHub上

說(shuō)一下demo中的實(shí)現(xiàn)方式

在 activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/activity_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <EditText
    android:id="@+id/edt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
  <Button
    android:id="@+id/btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="確定" />
  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.zhy.view.flowlayout.TagFlowLayout
      android:id="@+id/id_flowlayout"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      app:max_select="-1" />
  </ScrollView>
</LinearLayout>

實(shí)現(xiàn)模擬搜索效果圖

這里寫圖片描述

MainActivity.Java 代碼

public class MainActivity extends AppCompatActivity {
  private TagFlowLayout mFlowLayout;
  private EditText editText;
  private Button button;
  private List<String> strings;
  //布局管理器
  private LayoutInflater mInflater;
  //流式布局的子布局
  private TextView tv;
  public Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
        case 1:
          mFlowLayout.setAdapter(new TagAdapter<String>(strings) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
              tv = (TextView) mInflater.inflate(R.layout.tv,
                  mFlowLayout, false);
              tv.setText(s);
              return tv;
            }
          });
          break;
      }
      super.handleMessage(msg);
    }
  };
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mInflater = LayoutInflater.from(this);
    mFlowLayout = (TagFlowLayout) findViewById(R.id.id_flowlayout);
    editText = (EditText) findViewById(R.id.edt);
    button = (Button) findViewById(R.id.btn);
    strings = new ArrayList<>();
    button.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        String aa = editText.getText().toString().trim();
        strings.add(aa);
        //通知handler更新UI
        handler.sendEmptyMessageDelayed(1, 0);
      }
    });
    //流式布局tag的點(diǎn)擊方法
    mFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
      @Override
      public boolean onTagClick(View view, int position, FlowLayout parent) {
        Toast.makeText(MainActivity.this, tv.getText(), Toast.LENGTH_SHORT).show();
        return true;
      }
    });
  }

當(dāng)我們點(diǎn)擊確定按鈕的時(shí)候,通知handler 去更新UI界面

效果圖如下:

這里寫圖片描述

這樣就實(shí)現(xiàn)了一個(gè)簡(jiǎn)單的流式布局歷史搜索記錄

GitHub地址:https://github.com/zhangliyong114/FlowLayoutDemo

以上所述是小編給大家介紹的Android流式布局實(shí)現(xiàn)歷史搜索記錄功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • 保存ListView上次的滾動(dòng)條的位置實(shí)例(必看)

    保存ListView上次的滾動(dòng)條的位置實(shí)例(必看)

    下面小編就為大家?guī)?lái)一篇保存ListView上次的滾動(dòng)條的位置實(shí)例(必看)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀

    Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀

    這篇文章主要為大家介紹了Kotlin?協(xié)程的取消機(jī)制詳細(xì)解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • Android bindservice失敗解決方法

    Android bindservice失敗解決方法

    這篇文章主要介紹了Android bindservice失敗解決方法的相關(guān)資料,希望通過(guò)本文能幫助大家解決這樣的問(wèn)題,需要的朋友可以參考下
    2017-08-08
  • Android貝塞爾曲線實(shí)現(xiàn)加入購(gòu)物車拋物線動(dòng)畫

    Android貝塞爾曲線實(shí)現(xiàn)加入購(gòu)物車拋物線動(dòng)畫

    這篇文章主要為大家詳細(xì)介紹了Android貝塞爾曲線實(shí)現(xiàn)加入購(gòu)物車拋物線動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • Android學(xué)習(xí)筆記-保存數(shù)據(jù)到SQL數(shù)據(jù)庫(kù)中(Saving Data in SQL Databases)

    Android學(xué)習(xí)筆記-保存數(shù)據(jù)到SQL數(shù)據(jù)庫(kù)中(Saving Data in SQL Databases)

    這篇文章主要介紹了Android學(xué)習(xí)筆記-保存數(shù)據(jù)到SQL數(shù)據(jù)庫(kù)中的(Saving Data in SQL Databases)
    2014-10-10
  • Android藍(lán)牙開(kāi)發(fā)深入解析

    Android藍(lán)牙開(kāi)發(fā)深入解析

    由于近期正在開(kāi)發(fā)一個(gè)通過(guò)藍(lán)牙進(jìn)行數(shù)據(jù)傳遞的模塊,在參考了有關(guān)資料,并詳細(xì)閱讀了Android的官方文檔后,總結(jié)了Android中藍(lán)牙模塊的使用
    2013-10-10
  • Android獲取經(jīng)緯度計(jì)算距離介紹

    Android獲取經(jīng)緯度計(jì)算距離介紹

    Android提供LocationManager和Location,可以方便的獲得經(jīng)緯度、海拔等位置。使用LocationManager來(lái)獲得位置管理類,從而可以獲得歷史GPS信息以及位置變化的監(jiān)聽(tīng)注冊(cè);使用Location來(lái)獲得具體的位置信息
    2014-01-01
  • Android實(shí)現(xiàn)可以展開(kāi)的TextView

    Android實(shí)現(xiàn)可以展開(kāi)的TextView

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)可以展開(kāi)的TextView,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Android如何解析異構(gòu)列表

    Android如何解析異構(gòu)列表

    這篇文章主要介紹了Android如何解析異構(gòu)列表,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-03-03
  • Flutter 假異步的實(shí)現(xiàn)示例

    Flutter 假異步的實(shí)現(xiàn)示例

    這篇文章主要介紹了Flutter 假異步的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評(píng)論