3

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

我想使用 AutoCompleTextView 来过滤基于自定义 BaseAdapter 的 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 的示例。你能帮我么?提前致谢

4

1 回答 1

0

而不是使用你可以使用edittext和listview来做到这一点。您可以将 textwatcher 和自定义列表视图与图像一起使用

于 2015-09-18T08:36:21.300 回答