【问题标题】:Custom layout item list result of suggestion of search view of action bar动作栏搜索视图建议的自定义布局项列表结果
【发布时间】:2015-05-07 18:29:45
【问题描述】:

我在操作栏中从网络服务获取建议进行搜索。我已经用文字设置了建议。但我需要为项目添加图标,看起来像图片。那么如何在操作栏中的搜索视图建议中自定义项目的布局?

例子:

【问题讨论】:

  • 您必须使用带有图像和文本的自定义布局,并将布局设置为建议。
  • @Surender Kumar。能不能给我演示一下。我在谷歌上研究,但我没有看到任何演示。

标签: android android-actionbar searchview


【解决方案1】:

首先,您必须为您的自定义视图编写一个适配器。示例代码;

类 KitapFiltreAdapter(context:Context, @LayoutRes 私有 val layoutRes:Int, val kitapListe:ArrayList):ArrayAdapter(context,layoutRes,kitapListe){

private val inflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater;

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
    val view: View;
    view = inflater.inflate(layoutRes, parent, false);

    val kitapImage:ImageView = view.findViewById(R.id.searchItemImageId) as ImageView;
    val kitapAdTw:TextView = view.findViewById(R.id.searchKitapAdItemId) as TextView;
    val yazarAdTw:TextView = view.findViewById(R.id.searchKitapYazarAdItemId) as TextView;
    val kitap:KitapModel = getItem(position) as KitapModel;

    Glide.with(context).load(kitap.kitapResimPath).into(kitapImage);
    if(kitap.kitapAd!!.length>24){
        kitapAdTw.text     = kitap.kitapAd!!.substring(0,23)+"...";
    }else{
        kitapAdTw.text     = kitap.kitapAd;
    }

    yazarAdTw.text = kitap.yazarAd;

    return view;
}

override fun getItem(position: Int): KitapModel? {
    return kitapListe.get(position);
}

}

那么你可以像这样设置这个适配器;

searchView.findViewById<AutoCompleteTextView>(R.id.search_src_text).setAdapter(KitapFiltreAdapter(applicationContext,R.layout.kitap_search_item_layout,liste));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多