我有一个列表视图,如果值为0,则附加图像,如果不是1。 值0和1派生自SQLdatabase
我无法理解为什么第一行总是显示图像,如果它被标记为1,xml文本只有一个ImageView和textView,所以我不发送给你
public class CustomViewAdapter extends CursorAdapter {
public final int VIEW_TYPE_STARS=0;
public final int VIEWTYPE_NORMAL=1;
public static class ViewHolder{
public final ImageView iv;
public final TextView tv;
public ViewHolder(View view){
iv = (ImageView) view.findViewById(R.id.urgent_finger);
tv = (TextView) view.findViewById(R.id.text_v1);
}
}
public CustomViewAdapter(Context context,Cursor c, int flag){
super( context, c, flag);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
int viewType = getItemViewType(cursor.getPosition());
int layoutId=-1;
layoutId = R.layout.textview_pretty_cool2_layout;
View view= LayoutInflater.from(context).inflate(layoutId, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
view.setTag(viewHolder);
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder viewHolder= (ViewHolder) view.getTag();
String isCheckedMaybe = cursor.getString(cursor.getColumnIndexOrThrow(UcanContract.Tasks.COLUMN_URGENCY));
Integer toString = Integer.parseInt(isCheckedMaybe);
if(toString==0){
viewHolder.iv.setImageResource(R.drawable.edit_undo);
String tasksText = cursor.getString(cursor.getColumnIndexOrThrow(UcanContract.Tasks.COLUMN_TASKS));
viewHolder.tv.setText(tasksText);
}else if (toString == 1){
String tasksText = cursor.getString(cursor.getColumnIndexOrThrow(UcanContract.Tasks.COLUMN_TASKS));
viewHolder.tv.setText(tasksText);
}
}
}
答案 0 :(得分:1)
设置Visisbility
&的ImageView
{GES} {G} {当你需要它时,你将它设置为TextView
并且它会对你有用