其他分享
首页 > 其他分享> > android-listview中的自定义控件(旋转器)向我显示重复信息

android-listview中的自定义控件(旋转器)向我显示重复信息

作者:互联网

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

我正在ListView中自定义Spinner
在不使用自定义Spinner之前,它一直有效,并将标题和说明显示为:

标题1说明1

标题2说明2

标题3说明3

标题4说明4

标题5说明5

标题6说明6

标题7说明7

但是,当我使用“自定义微调器”时,它会显示以下信息:

标题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: 

它有效,但不会显示在列表视图中

解决方法:

采用:

 public StructNote note;

并循环调用它:

 note = new StructNote();

对于每个新笔记使用

new …

标签:listview,custom-controls,android
来源: https://codeday.me/bug/20191121/2054710.html