Android ListView 在滚动时切断列表中字符串的末尾

发布于 2025-01-08 07:22:55 字数 1846 浏览 1 评论 0原文

我使用来自不同地方的一些示例代码编写了一个ListView,尽管适配器的动态设置正在工作,但由于某种原因,当我滚动到不同的位置时,列表中字符串的末尾会神奇地消失。这是为什么呢?适配器的代码是这样的: 另外,列表 xml 只是标准列表视图,没有子级。子项是由该适配器添加的。

package com.vrise.bellarmine;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

class EfficientAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private String[] gradesName;
    private String[] gradesVal;
    public EfficientAdapter(Context context, String[] gradesname, String[] gradesval) {
        mInflater = LayoutInflater.from(context);
        gradesName = gradesname;
        gradesVal = gradesval;
    }

    public int getCount() {
        return gradesName.length;
    }

    public Object getItem(int position) {
        return position;
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.row, null);
            holder = new ViewHolder();
            holder.text1 = (TextView) convertView
                    .findViewById(R.id.TextView01);
            holder.text2 = (TextView) convertView
                    .findViewById(R.id.TextView02);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text1.setText(gradesName[position]);
        holder.text2.setText(gradesVal[position]);

        return convertView;
    }

    static class ViewHolder {
        TextView text1;
        TextView text2;
    }
}

另外,由于某种原因,我无法添加图片。 但它看起来是这样的:列表正在滚动,当我向上滚动时,开始的“Calculus AB AP”现在是“Calcu”。

I wrote a ListView using some sample code from different places, and although the dynamic setting of the Adapter is working, for some reason, when I scroll to a different position, the ends of the strings in the list will magically dissappear. Why is this? The code for the adapter is this: Also, the list xml is just standard listview with no children. The children are added by this adapter.

package com.vrise.bellarmine;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

class EfficientAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private String[] gradesName;
    private String[] gradesVal;
    public EfficientAdapter(Context context, String[] gradesname, String[] gradesval) {
        mInflater = LayoutInflater.from(context);
        gradesName = gradesname;
        gradesVal = gradesval;
    }

    public int getCount() {
        return gradesName.length;
    }

    public Object getItem(int position) {
        return position;
    }

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.row, null);
            holder = new ViewHolder();
            holder.text1 = (TextView) convertView
                    .findViewById(R.id.TextView01);
            holder.text2 = (TextView) convertView
                    .findViewById(R.id.TextView02);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text1.setText(gradesName[position]);
        holder.text2.setText(gradesVal[position]);

        return convertView;
    }

    static class ViewHolder {
        TextView text1;
        TextView text2;
    }
}

Also I for some reason can't add pics.
But what it looks like is: The list is scrolling, and when I scroll back up, what started out as "Calculus AB AP" is now "Calcu".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文