0

我今天一直在阅读有关多列列表视图的信息。它们似乎是我需要的,但无法提供有关如何在不使用哈希映射的情况下填充它们的信息。我见过的所有示例都使用哈希映射来构建列表视图数据适配器,但是当隐含大量数据时,这太重了。无论如何要填充没有哈希列表的列表视图吗?

我见过的所有例子都使用这样的东西: http ://saigeethamn.blogspot.com.es/2010/04/custom-listview-android-developer.html

4

1 回答 1

0

是的,有可能。请查看代码。

public class List_view_ArrayAdapter extends ArrayAdapter<String> {
    private Context context;
    private String[] name;
    private String[] address;
    private String[] rating;
    private TextView nameTextView;
    private TextView addressTextView;
    private ImageView lisiconImageView;
    private AppManagers appManagers;

    public List_view_ArrayAdapter(Context context, String[] name,
            String[] address, String[] rating) {
        super(context, R.layout.list_layout, name);
        this.context = context;
        this.name = name;
        this.address = address;
        this.rating = rating;
        appManagers = new AppManagers();

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_layout, parent, false);
        nameTextView = (TextView) rowView.findViewById(R.id.nameTextView);
        addressTextView = (TextView) rowView.findViewById(R.id.addressTextView);

        lisiconImageView = (ImageView) rowView
                .findViewById(R.id.listiconImageView);
        nameTextView.setText(name[position]);
        addressTextView.setText(address[position]);

        lisiconImageView.setImageDrawable(appManagers
                .ImageOperations(rating[position]));
        // imageView.setImageResource(imageid[position]);
        return rowView;
    }

}

这是这一行“R.layout.list_layout”的list_layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" android:background="#d9d9d9">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" android:layout_marginBottom="5dp" android:layout_marginTop="5dp">

        <ImageView
            android:id="@+id/listiconImageView"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" android:layout_marginLeft="5dp" android:gravity="center_vertical" android:layout_marginBottom="5dp" android:layout_marginTop="5dp">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Name : "
                android:textColor="#2a170e" />

            <TextView
                android:id="@+id/nameTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView"
                android:textColor="#2a170e" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Address : "
                android:textColor="#2a170e" />

            <TextView
                android:id="@+id/addressTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView"
                android:textColor="#2a170e" />
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

最后你从你的主要活动中调用它。

new List_view_ArrayAdapter arrayAdapter= new List_view_ArrayAdapter(context, appManagers.getNameArray(cafeandbarsList), name, address, rating); 

listView.setAdapter(arrayAdapter);

我认为它对你有帮助。

谢谢

于 2012-06-14T16:17:19.903 回答