android - 使用 AutoCompleTextView 基于 BaseAdapter 过滤带图像的 Listview

标签 android listview filter baseadapter

我是 Android 新手,所以请耐心等待!

我想使用 AutoCompleTextView 来过滤基于自定义 BaseAdapter 的 ListView。此 ListView 包含文本和图像。

这是 ListView 的布局:

listview_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/backrepeat_dark"
android:padding="0sp" >


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/options_bar"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >

    <AutoCompleteTextView
        android:id="@+id/inputSearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Ricerca opere..."
        android:inputType="textVisiblePassword"
        android:textSize="12dp" >

</AutoCompleteTextView>

     <ListView
         android:id="@+id/list"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_above="@+id/options_bar"
         android:layout_weight="1"
         android:cacheColorHint="#80000000"
         android:divider="#b5b5b5"
         android:dividerHeight="1dp" />

</LinearLayout>

<include
    android:id="@+id/options_bar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="0dp"
    android:layout_weight="0"
    layout="@layout/menu_main"
    android:fadingEdge="horizontal" />

</RelativeLayout>

这里是列表行布局:

list_row.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >

<LinearLayout
    android:id="@+id/thumbnail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="5dip"
    android:padding="3dip" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="100dp"
        android:layout_height="100dp" />
</LinearLayout>

<TextView
    android:id="@+id/pid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_marginRight="5dip"
    android:gravity="right"
    android:text="5:45"
    android:textColor="#10bcc9"
    android:textSize="10dip"
    android:textStyle="bold"
    android:visibility="gone" />

<!-- Rightend Arrow -->

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:src="@drawable/arrow" />

<TextView
    android:id="@+id/name"
    style="?textLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/thumbnail"
    android:layout_marginLeft="56dp"
    android:layout_toRightOf="@+id/thumbnail"
    android:text="TITOLO" />

<TextView
    android:id="@+id/autore"
    style="?textRegular"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/name"
    android:layout_below="@+id/name"
    android:text="Autore" />

</RelativeLayout>

这是我的自定义适配器:

public class LazyAdapterOpere extends BaseAdapter {

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;

public LazyAdapterOpere(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data = d;
    inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader = new ImageLoader(activity.getApplicationContext());
}

public int getCount() {
    return data.size();
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)

        vi = inflater.inflate(R.layout.list_row, null);

    TextView pid = (TextView) vi.findViewById(R.id.pid); 
    TextView name = (TextView) vi.findViewById(R.id.name); 
    TextView autore = (TextView) vi.findViewById(R.id.autore); 
    ImageView image = (ImageView) vi.findViewById(R.id.image); 

    HashMap<String, String> opere = new HashMap<String, String>();
    opere = data.get(position);

    // Setting all values in listview
    pid.setText(opere.get(ElencoOpere.TAG_PID));
    name.setText(opere.get(ElencoOpere.TAG_NAME));
    autore.setText(opere.get(ElencoOpere.TAG_AUTORE));

    imageLoader.DisplayImage(opere.get(ElencoOpere.TAG_IMAGE), image);
    return vi;
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

这就是我填充自定义适配器的方式:

ArrayList<HashMap<String, String>> listaOpere = new ArrayList<HashMap<String, String>>();


// products JSONArray
JSONArray opere = null;

ListView list;
LazyAdapterOpere adapter;


EditText inputSearch;

@Override
public void onCreate(Bundle savedInstanceState) {



    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview_main);

    addListenerOnButton();

    // Loading products in Background Thread
    new LoadAllProducts().execute();

    list=(ListView)findViewById(R.id.list);
    inputSearch = (EditText) findViewById(R.id.inputSearch);

    // getting product details from intent
    Intent i = getIntent();

    // getting product id (pid) from intent
    sala = i.getStringExtra(TAG_SALA);

        adapter=new LazyAdapterOpere(this, listaOpere);     
        adapter.imageLoader.clearCache();
        list.setAdapter(adapter);

一切正常,但我不知道如何使用此适配器的过滤器,我只看到 ArrayAdapter 的示例。 你能帮我么? 提前致谢

最佳答案

您可以使用 edittext 和 listview 来代替使用。你可以使用 textwatcher 和带有图像的自定义 ListView

关于android - 使用 AutoCompleTextView 基于 BaseAdapter 过滤带图像的 Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12371309/

相关文章:

android - 如何在 native react 中对 TextInput 应用点击事件

java - 如何在一个应用程序中的多个 Activity 之间共享蓝牙接收的数据

android - 如何像 WhatsApp 在 Firebase 聊天应用程序中那样从联系人列表中获取我的应用程序的所有用户

python - 从数据框中检索行以在数据框的列中与列表中的元素进行部分匹配

java - 这是自定义过滤器最有效的方法吗?

android - 按钮 setOnClickListener 上的 NullPointerException

android - kotlin 中的合成导入不起作用

c# - 从 ListView 检索到的错误数据

android - 如何在 setOnItemClickListener 部分更改 ListView 适配器

python - 使用其他模型的对象过滤对象