android - ListView 中的自定义控件(微调器)向我显示重复信息

标签 android listview custom-controls

ListView 中的自定义微调器向我显示重复信息

我在 ListView 中使用自定义 Spinner 在我不使用自定义微调器之前,它可以正常工作并将标题和描述显示为:

标题 1 描述 1

标题 2 描述 2

标题 3 描述 3

标题 4 描述 4

标题 5 描述 5

标题 6 描述 6

标题 7 描述 7

但是当我使用 Custom Spinner 时,它显示的信息如下:

标题 7 描述 7

标题 7 描述 7

标题 7 描述 7

标题 7 描述 7

标题 7 描述 7

标题 7 描述 7

标题 7 描述 7

它只显示最后的标题和描述。

在 AdapterNote.Java 类中:

package ir.redreactor.app.Com.NovinEr;

import java.util.ArrayList;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;

public class AdapterNote extends ArrayAdapter {

    public AdapterNote(ArrayList array) {
        super(G.context, R.layout.adapter_notes, array);
    }

    private static class ViewHolder {

        public ViewGroup LayoutRt;
        public TextView  txtTitle;
        public EditText  txtDetail;
        public TextView  txtTableName;
        public TextView  txtSort;
        public TextView  txtID;
        public TextView  txtpos;

        public ViewHolder(View view) {
            LayoutRt = (ViewGroup) view.findViewById(R.id.layout_Rt);
            txtTitle = (TextView) view.findViewById(R.id.txtTitleCS_One);
            txtDetail = (EditText) view.findViewById(R.id.edtContentCS_One);
            txtTableName = (TextView) view.findViewById(R.id.txtTableNameCS_One);
            txtSort = (TextView) view.findViewById(R.id.txtSortCS_One);
            txtID = (TextView) view.findViewById(R.id.txtIDCS_One);
            txtpos = (TextView) view.findViewById(R.id.txtPositionCS_One);
        }

        public void fill(ArrayAdapter Adapter, StructNote Item, final int position) {
            txtTitle.setText(Item.title);
            txtDetail.setText(Item.detail);
            txtTableName.setText(Item.nameOfTable);
            txtSort.setText(Item.Sort.toString());
            txtID.setText(Item.intID.toString());
            txtpos.setText("" + position);
        }
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        StructNote item = getItem(position);
        final ViewHolder holder;
        if (convertView == null) {
            convertView = G.inflater.inflate(R.layout.adapter_notes, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.fill(this, item, position);
        return convertView;
    }
}

在自定义微调器类“CS_One.java”中:

package ir.redreactor.app.Com.NovinEr;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CS_One extends LinearLayout {

    public CS_One(Context context) {
        super(context);
        initialize(context);
    }

    public CS_One(Context context, AttributeSet attrs) {
        super(context, attrs);
        initialize(context);
    }

    private void initialize(Context context) {
        //
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.cs, this, true);
        // Buttons
        Button btnSortCS_One = (Button) view.findViewById(R.id.btnSortCS_One);
        Button btnFavCS_One = (Button) view.findViewById(R.id.btnFavCS_One);
        Button btnShareCS_One = (Button) view.findViewById(R.id.btnShareCS_One);
        Button btnCopyCS_One = (Button) view.findViewById(R.id.btnCopyCS_One);
        Button btnSaveCS_One = (Button) view.findViewById(R.id.btnSaveCS_One);
        // Text Fields
        final EditText edtContentCS_One = (EditText) view.findViewById(R.id.edtContentCS_One);
        final TextView txtTitleCS_One = (TextView) view.findViewById(R.id.txtTitleCS_One);
        TextView txtGreenCS_One = (TextView) view.findViewById(R.id.txtGreenCS_One);
        TextView txtBlueCS_One = (TextView) view.findViewById(R.id.txtBlueCS_One);
        TextView txtYelloCS_One = (TextView) view.findViewById(R.id.txtYelloCS_One);
    }
}

LayoutRt 已在“adapter_notes.xml”中定义,因此其他项目在“cs.xml”中定义(cs.xml 是自定义微调器的 XML)

如何解决?


我使用了 logcat:

Log.i("tst", "G.Note.Size Is: " + G.notes.size());
Log.i("tst", "note.title  Is: " + note.title);
Log.i("tst", "note.detail Is: " + note.detail);

它告诉我:

04-24 08:27:30.482: I/tst(309): G.Note.Size Is: 1
04-24 08:27:30.482: I/tst(309): note.title  Is: ???
04-24 08:27:30.482: I/tst(309): note.detail Is: hossein
04-24 08:27:30.482: I/tst(309): G.Note.Size Is: 2
04-24 08:27:30.482: I/tst(309): note.title  Is: ??? ????????
04-24 08:27:30.482: I/tst(309): note.detail Is: kurd
04-24 08:27:30.492: I/tst(309): G.Note.Size Is: 3
04-24 08:27:30.492: I/tst(309): note.title  Is: ????? ???
04-24 08:27:30.492: I/tst(309): note.detail Is: 
04-24 08:27:30.492: I/tst(309): G.Note.Size Is: 
04-24 08:27:30.492: I/tst(309): note.title  Is: ??? ???? ??? ????
04-24 08:27:30.492: I/tst(309): note.detail Is: 
04-24 08:27:30.492: I/tst(309): G.Note.Size Is: 5
04-24 08:27:30.492: I/tst(309): note.title  Is: ?? ????
04-24 08:27:30.492: I/tst(309): note.detail Is: 
04-24 08:27:30.492: I/tst(309): G.Note.Size Is: 6
04-24 08:27:30.492: I/tst(309): note.title  Is: ??? ???? ??? ????
04-24 08:27:30.492: I/tst(309): note.detail Is: 
04-24 08:27:30.501: I/tst(309): G.Note.Size Is: 7
04-24 08:27:30.501: I/tst(309): note.title  Is: ??? ???
04-24 08:27:30.501: I/tst(309): note.detail Is: 
04-24 08:27:30.501: I/tst(309): G.Note.Size Is: 8
04-24 08:27:30.501: I/tst(309): note.title  Is: ????? ????????
04-24 08:27:30.501: I/tst(309): note.detail Is: 
04-24 08:27:30.501: I/tst(309): G.Note.Size Is: 9
04-24 08:27:30.501: I/tst(309): note.title  Is: ????? ????
04-24 08:27:30.501: I/tst(309): note.detail Is: 

它有效,但它不显示在 ListView 中

最佳答案

使用:

 public StructNote note;

并在循环中调用它:

 note = new StructNote();

对于每一个新的笔记使用

new ...

关于android - ListView 中的自定义控件(微调器)向我显示重复信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23244046/

相关文章:

Android在滚动结束时动态加载Listview?

Android:断开蓝牙耳机以使用蓝牙连接我的 SPP 应用程序

java - Firebase 用户界面 : RecyclerView items are not shown

android - 禁用 Listview 项目单击并重新启用它

java - Android - 更改ListView项目的TextStyle

php - 如何使用 PHP 从 Mysql 数据库获取结果创建多项选择 Android ListView ?

c# - 将自定义设计时命令添加到 WinForms 控件

Android 小部件 - 在哪里注册显式广播

android - Canvas 上字符串的简单淡出动画,android

android - 自定义 View 不响应触摸