listview中的自定义控件(微调器)向我显示重复信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
对于每个新笔记使用
新...
以上是关于listview中的自定义控件(微调器)向我显示重复信息的主要内容,如果未能解决你的问题,请参考以下文章