当我向下滚动,如果我在列表中上升,适配器仅加载图标和文本。如果我没有在适配器中设置可绘制,则 texview 可以正常绘制,但我想务实地更改我的图标。我可以看到android dev将在 api 级别 17 中得到支持,但现在我无法在我的适配器中使用它,有没有办法解决这个问题?
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:padding="4dp"
android:drawablePadding="4dp"
android:drawableLeft="@drawable/file"
PROBLEM -> android:drawableEnd="@drawable/next" >
</TextView>
和我的适配器代码:
public class MyAdapter extends ArrayAdapter<String> {
Context context;
int layout_resourceId;
ArrayList<String> list_text;
public MyAdapter(Context context, int layout_resourceId, ArrayList<String> list_text) {
super(context, layout_resourceId, list_text);
this.context = context;
this.layout_resourceId = layout_resourceId;
this.list_text = list_text;
}
@Override
public View getView(int position, View convert_view, ViewGroup parent) {
View row = convert_view;
MyItemHolder holder = null;
if(row == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layout_resourceId, parent, false);
holder = new MyItemHolder();
holder.text_view = (TextView)row.findViewById(R.id.item);
holder.icon_view = (TextView)row.findViewById(R.id.item);
row.setTag(holder);
}
else {
holder = (MyItemHolder)row.getTag();
}
//text
String string_item = list_text.get(position);
holder.text_view.setText(string_item);
//icon
MyExtension.myExtension(string_item);
int drawable = MyExtension.file_icon_is;
holder.icon_view.setCompoundDrawablesWithIntrinsicBounds(drawable, 0, 0, 0);
return row;
}
public static class MyItemHolder {
TextView icon_view;
TextView text_view;
}
}