Use:
public StructNote note;
and in cycle call it:
note = new StructNote();
For Every New note Use
new ...
Question
custom spinner in listview show me repetitious Information
I am auing custom Spinner in ListView Until I don't use custom Spinner it works and shows me title and description as:
Title 1 Description 1
Title 2 Description 2
Title 3 Description 3
Title 4 Description 4
Title 5 Description 5
Title 6 Description 6
Title 7 Description 7
But When I Use Custom Spinner It Shows Me Information as:
Title 7 Description 7
Title 7 Description 7
Title 7 Description 7
Title 7 Description 7
Title 7 Description 7
Title 7 Description 7
Title 7 Description 7
It Shows Only Last Title And Description.
In Class 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;
}
}
In Custom Spinner Class "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 has Defined At "adapter_notes.xml" So Other Items Defined At "cs.xml"(cs.xml Is XML As For Custom Spinner)
How To Fix It?
I used 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);
it show me:
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:
it works, but it doesnt show in the list view
Solution
Use:
public StructNote note;
and in cycle call it:
note = new StructNote();
For Every New note Use
new ...