大佬教程收集整理的这篇文章主要介绍了android – ListView with ArrayAdapter和ViewHolder将图标添加到错误的项目,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
通常一切都很好(名称正确地@L_@R_772_11241@_5@到列表中,与图标一起).但是显示性别的图标会被@L_@R_772_11241@_5@到ListView中的错误项目中.名称将@L_@R_772_11241@_5@到列表的底部,但图标将放置在列表顶部的名称处.我不知道这是否是我使用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(@R_450_2196@,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 prev@R_419_2469@sly 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);
public View getView(@R_450_2196@,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",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); 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. if (sexmale == truE) { holder.icon.setImageBitmap(maleicon); } else { holder.icon.setImageBitmap(femaleicon); } Log.i("Andy","getCount = "+mAdapter.getCount()); return convertView; }
以上是大佬教程为你收集整理的android – ListView with ArrayAdapter和ViewHolder将图标添加到错误的项目全部内容,希望文章能够帮你解决android – ListView with ArrayAdapter和ViewHolder将图标添加到错误的项目所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。