国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現簡單實用的搜索框

2020-02-21 17:21:40
字體:
來源:轉載
供稿:網友

Android開發中,很多實現效果還是動態最能受到大家的歡迎,而搜索框也是很常見的,但在Android開發中沒有現成的控件,下面武林技術頻道小編給大家介紹Android實現簡單實用的搜索框。

展示效果

這里寫圖片描述

代碼區

SouActivity

public class SouActivity extends AppCompatActivity implements TextWatcher{  @BindView(R.id.app_sou)  EditText appSou;  @BindView(R.id.app_sou_list)  ListView appSouList;  @BindView(R.id.activity_sou)  RelativeLayout activitySou;  private String mUrl = "http://120.27.23.105/product/searchProducts";  private List<MySouFr.DataBean> sdata;  private MyBase myBase;  private String asou;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_sou);    ButterKnife.bind(this);    sdata=new ArrayList<MySouFr.DataBean>();    appSou.addTextChangedListener(this);    appSou.setOnFocusChangeListener(new View.OnFocusChangeListener() {      @Override      public void onFocusChange(View view, boolean b) {        if(b)        {          appSou.setText("");        }      }    });  }  @Override  public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {  }  @Override  public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {    //獲取輸入框的值    asou = appSou.getText().toString().trim();      OkHttp3Utils.getInstance().doGet(mUrl + "?keywords=" + asou + "&page=1", new GsonObjectCallback<MySouFr>() {        @Override        public void onUi(final MySouFr mySouFr) {          /*適配器*/          if (asou !=null&&!asou.equals("")) {            sdata = mySouFr.getData();            myBase = new MyBase();            appSouList.setAdapter(myBase);            appSouList.setOnItemClickListener(new AdapterView.OnItemClickListener() {              @Override              public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {                Intent intent = new Intent(SouActivity.this, Sou_item_Activity.class);                intent.putExtra("url",mySouFr.getData().get(i).getDetailUrl());                startActivity(intent);//                Toast.makeText(SouActivity.this, "假裝你已經點擊了哦!", Toast.LENGTH_SHORT).show();              }            });          } else if(myBase!=null) {            sdata.clear();            myBase.notifyDataSetChanged();          }        }        @Override        public void onFailed(Call call, IOException e) {        }      });    }  @Override  public void afterTextChanged(Editable editable) {  }  class MyBase extends BaseAdapter{    @Override    public int getCount() {      return sdata.size();    }    @Override    public Object getItem(int i) {      return sdata.get(i);    }    @Override    public long getItemId(int i) {      return i;    }    @Override    public View getView(int i, View view, ViewGroup viewGroup) {      Vh vh=null;      if(view==null){        view=View.inflate(SouActivity.this,R.layout.item_sou,null);        vh=new Vh();        vh.tv1=(TextView) view.findViewById(R.id.item_sou_text1);        view.setTag(vh);      }else{        vh = (Vh) view.getTag();      }      Log.d("main",sdata.get(i).getTitle());      vh.tv1.setText(sdata.get(i).getTitle());      return view;    }  }  class Vh{    TextView tv1;  }}

activity_sou

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:id="@+id/activity_sou"  android:layout_width="match_parent"  android:layout_height="match_parent"  tools:context="sizu.nsg.SouActivity">  <EditText    android:id="@+id/app_sou"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:hint="Searching..."    />  <ListView    android:id="@+id/app_sou_list"    android:layout_below="@id/app_sou"    android:layout_width="match_parent"    android:layout_height="match_parent">  </ListView></RelativeLayout>


item_sou

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent">  <TextView    android:id="@+id/item_sou_text1"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:text="123"    /></RelativeLayout>

以上就是武林技術頻道小編給大家介紹的Android實現簡單實用的搜索框,相關內容就介紹到這里了,還想了解更多請繼續關注js.Vevb.com吧!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 招远市| 延川县| 海安县| 加查县| 高唐县| 化德县| 塘沽区| 龙陵县| 安吉县| 凌海市| 万山特区| 富蕴县| 河东区| 雷山县| 阿拉善左旗| 弥渡县| 瑞丽市| 萨嘎县| 赤水市| 高密市| 汾阳市| 洪洞县| 奎屯市| 衡南县| 彭泽县| 改则县| 古交市| 盐亭县| 威宁| 齐河县| 隆回县| 昌吉市| 凌海市| 宝应县| 大新县| 达孜县| 文成县| 兴山县| 精河县| 贵溪市| 扶绥县|