---代码---
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder vHolder=null;
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.drawer, null, false);
vHolder = new ViewHolder();
TextView tCategory = (TextView) view.findViewById(R.id.category);
TextView tPosition = (TextView) view.findViewById(R.id.position);
vHolder.tCategory = tCategory;
vHolder.tPosition = tPosition;
view.setTag(vHolder);
}else {
vHolder = (ViewHolder) view.getTag();
}
String[] split = getItem(position).split("£");
String category = split[0].trim();
Integer catID = Integer.parseInt(split[1].trim());
vHolder.tCategory.setTag(catID);
vHolder.tPosition.setTag(catID + "_position");
if(SZ.CURRENTCATEGORY == catID) {
vHolder.tCategory.setText("TOP: " + category);
}else{
vHolder.tCategory.setText(category);
}
AbsListView.LayoutParams params = (AbsListView.LayoutParams) view.getLayoutParams();
if(catID >= 90){//SUBJECT
vHolder.tCategory.setTextSize( context.getResources().getDimension(R.dimen.drawer_subject));
vHolder.tCategory.setTextColor(context.getResources().getColor(R.color.drawer_subject));
vHolder.tCategory.setTypeface(null, Typeface.BOLD);
vHolder.tCategory.setGravity(Gravity.CENTER_HORIZONTAL);
vHolder.tCategory.setPadding(5, 0, 20, 0);
view.setPressed(false);
view.setBackgroundColor(Color.DKGRAY);
vHolder.tPosition.setVisibility(View.GONE);
}else{//CATEGORY
if (vHolder.tPosition.getText().toString().trim().equalsIgnoreCase("") && vHolder.tPosition.getText().toString().indexOf("0") == -1) {
vHolder.tPosition.setText("0");
int position = SZ.position(catID);
if (position > 0) {
vHolder.tPosition.setText("" + position);
}
}
vHolder.tPosition.setVisibility(View.VISIBLE);
vHolder.tCategory.setTextSize(context.getResources().getDimension(R.dimen.drawer_category));
vHolder.tCategory.setTextColor(context.getResources().getColor(R.color.drawer_category));
vHolder.tCategory.setTypeface(null, Typeface.NORMAL);
vHolder.tCategory.setGravity(Gravity.NO_GRAVITY);
vHolder.tCategory.setPadding(0, 5, 0, 0);
view.setPressed(true);
view.setBackgroundColor(Color.TRANSPARENT);
}
return view;
}
我在Android模拟器上运行了我的代码。当我打开我的导航抽屉时,当我向下滚动列表或向上滚动我的类别位置值(vHolder.tPosition)时,任意正常工作但 ...
我搜索更多时间来解决此问题,并使用ViewHolder模式但未解决。 那我怎么能解决这个问题呢? (谢谢)
Sory因为我的英语不好。