Example code of Android bsearchedit search result selection box

EditText search results drop-down @ r_378_2419 @, auto or callback mode, DIY, easy to use

GitHub address

YangsBryant/BSearchEdit

(GitHub has a good layout. It is recommended to check the details here. If you feel good, click star!)

Import module

allprojects {
  repositories {
    google()
    jcenter()
    maven { url 'https://www.jitpack.io' }
  }
}
implementation 'com.github.YangsBryant:BSearchEdit:1.0.4'
 #支持自动展示搜索条目
#支持手动展示搜索条目(可自己记录历史数据,可等请求回调后弹出搜索条目)

#背景支持颜色,selector,图片等资源属性

Bsearchedit attribute Encyclopedia

critical code

EditText editText = findViewById(R.id.edit_text);//获取一个EditText
 bSearchEdit = new BSearchEdit(this,editText,200);//第三个必须要设置窗体的宽度,单位dp
 bSearchEdit.build();
 //更新数据
 bSearchEdit.setSearchList(list);
#Tips:遇到is your activity running? 那是因为activity还未创建,showPopup()调用的太早了

Demo code

public class MainActivity extends AppCompatActivity {
  private ArrayList<String> list;
  private BSearchEdit bSearchEdit;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    list = new ArrayList<>();
    list.add("江西省赣州市");
    list.add("广东省深圳市");
    list.add("广东省珠海市");
    EditText editText = findViewById(R.id.edit_text);
    bSearchEdit = new BSearchEdit(this,200);
    bSearchEdit.build();
    bSearchEdit.setSearchList(list);
    bSearchEdit.setTextClickListener(new BSearchEdit.TextClickListener() {
      @Override
      public void onTextClick(int position,String text) {
        Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show();
      }
    });
    Button button01 = findViewById(R.id.button01);
    button01.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        list.clear();
        list.add("小米 9pro");
        list.add("华为 mate30");
        list.add("vivo nex3");
        list.add("iPhone 11");
        bSearchEdit.setSearchList(list);
        Toast.makeText(MainActivity.this,"更新数据成功",Toast.LENGTH_SHORT).show();
      }
    });
    Button button02 = findViewById(R.id.button02);
    button02.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        list.clear();
        list.add("瑞士民众抵制5G");
        list.add("威马汽车起火");
        list.add("王者荣耀新英雄西施");
        list.add("黄渤出演姜子牙");
        list.add("北京天空飞机刷屏");
        list.add("Kimi名字由来");
        bSearchEdit.setSearchList(list);
        Toast.makeText(MainActivity.this,Toast.LENGTH_SHORT).show();
      }
    });
  }
}

summary

The above is the example code of Android bsearchedit search result selection box introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support to our website! If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>