Android的,ListView和ArrayAdaptater,getView调用一次 [英] Android, ListView and ArrayAdaptater, getView called only once

查看:146
本文介绍了Android的,ListView和ArrayAdaptater,getView调用一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示在列表视图的一些数据。我的问题是,只有一个项目是在我的列表视图所示。

I'm trying to show some data on a listview. My problem is that only one item is shown in my listview.

我在这里发现了许多主题有关,但没有帮助我。

I've found many topics about here but none helped me.

我已经看到getView()方法被调用一次(我检查了我的列表,它的大小为178)。

I've see that the getView() method is called only once (I checked my list, and it's size is 178).

下面是我的code:

public class RiverListArrayAdaptater extends ArrayAdapter<LinkedList<River>> {

    private Context context;
    private LinkedList<River> list;

    public RiverListArrayAdaptater(Context context,LinkedList<River> list) {
        super(context,R.layout.list_river);
        this.context = context;
        this.list = list;
    }

    public View getView(int pos, View convertView, ViewGroup parent) {
        // Get variables
        LayoutInflater inflater = (LayoutInflater) cont        ext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);       
        View rowView = inflater.inflate(R.layout.list_river, parent, false);
        TextView textViewName = (TextView) rowView.findViewById(R.id.name);
        TextView textViewValue = (TextView) rowView.findViewById(R.id.value);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
        textViewName.setText(list.get(pos).getName());
        textViewValue.setText(list.get(pos).getDebit());
        imageView.setImageResource(R.drawable.down);

        return rowView;
    }

}

我的code在OnCreate():

My code in the onCreate():

    LinkedList<River> list = parser.parse(getter.getData());
            RiverListArrayAdaptater adaptater = new     RiverListArrayAdaptater(this,list);
            adaptater.notifyDataSetChanged();
            adaptater.add(list);
            list1.setAdapter(adaptater);

在这里,我的两个XML文件:

And here my two XML file:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

     <ListView
        android:id="@+id/listRiver"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
      />

</RelativeLayout>

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/logo"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="5dp"
        android:contentDescription="@+id/up_or_down"
        >
    </ImageView>

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp" >
    </TextView>

    <TextView
        android:id="@+id/value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp" >
    </TextView>

</LinearLayout>

THX你的时间...

Thx for your time...

推荐答案

您需要重写getCount将在ArrayAdapter并返回多少项目在列表中。

You need to override getCount in your ArrayAdapter and return how many items are in the list.

检查<一个href=\"https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/ArrayAdapter.java\"相对=nofollow>来源ArrayAdapter 获取更多信息。

这篇关于Android的,ListView和ArrayAdaptater,getView调用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆