customerAdapter 的第一行不起作用
the first row of the customerAdapter does not work
我有一个列表视图,如果值为 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);
}
}
}
将您的 ImageView
和 TextView
的 Visisbility
设置为 GONE,当您需要它时,将其设置为 VISISBLE
它会为您工作
我有一个列表视图,如果值为 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);
}
}
}
将您的 ImageView
和 TextView
的 Visisbility
设置为 GONE,当您需要它时,将其设置为 VISISBLE
它会为您工作