पर आइकन जोड़ना मेरे पास गतिशील ListView
है जो ArrayAdapter
का उपयोग करता है। जब किसी स्पिनर से कोई नाम चुना जाता है, तो एक आइकन के साथ नाम दिखाता है कि वे नर या मादा हैं ListView
में जोड़े गए हैं।ArrayAdapter और ViewHolder के साथ ListView गलत आइटम
अधिकतर सबकुछ अच्छा है (नाम आइकन के साथ सही ढंग से सूची में जोड़ा जाता है)। लेकिन लिंग दिखाने वाला आइकन ListView
में गलत आइटम में जोड़ा जाता है। नाम सूची के नीचे जोड़ा जाता है, लेकिन आइकन सूची के शीर्ष पर नाम पर रखा जाता है। मुझे नहीं पता कि मैं जिस तरह से ViewHolder
का उपयोग कर रहा हूं, लेकिन Android website में शून्य दस्तावेज है।
// Listview inflater
inflater = (LayoutInflater) (this).getSystemService(LAYOUT_INFLATER_SERVICE);
// List Array.
mAdapter = new ArrayAdapter<String>(this, R.layout.player_simple_list,
R.id.label, mStrings) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.i("ANDY","View getView Called");
// A ViewHolder keeps references to children views to
// avoid unneccessary calls to findViewById() on each row.
ViewHolder holder;
if (null == convertView) {
Log.i("ANDY","Position not previously used, so inflating");
convertView = inflater.inflate(R.layout.player_simple_list, null);
// Creates a ViewHolder and store references to the
// two children views we want to bind data to.
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.label);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
if (sexmale == true) {
holder.icon.setImageBitmap(maleicon);
}
else {
holder.icon.setImageBitmap(femaleicon);
}
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
holder.text.setText(getItem(position));
// Change icon depending is the sexmale variable is true or false.
Log.i("ANDY","getCount = "+mAdapter.getCount());
return convertView;
}
};
setListAdapter(mAdapter);
वहाँ वहाँ कुछ उचित प्रलेखन है: https://developer.android.com/training/improving-layouts/smooth-scrolling.html – Vince