1

在我的应用程序中,我有一个带有 textview 和复选框的 customlistview,这些值是从 bindview 调用的。我的问题是如果我将 5 个列表添加到视图中。删除线文本仅适用于最后一个复选框。我可以知道为什么在bindview中会出现这个问题。提前致谢。

public class CustomContacts extends SimpleCursorAdapter{
 private LayoutInflater mLayoutInflater;
// private Context context;
 private int col=0;
 private int col1=0;
 public static boolean itemreminder;
 int id;
 private TextView tcontent;
 int id1;
 private CheckBox check;
 public static int checkbox = 0;
 SwipeDetector swipedetector;
@SuppressWarnings("deprecation")
public CustomContacts(Context context, int layout, Cursor c, String[] from,
        int[] to) {
    super(context, layout, c, from, to);
    // TODO Auto-generated constructor stub
     mLayoutInflater = LayoutInflater.from(context);

}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    return mLayoutInflater.inflate(R.layout.activity_contactitem, null);
}
@Override
public void bindView(View view, final Context context, final Cursor c) {   
    final int id = c.getInt(c.getColumnIndex(Contactsnew.userid));
    Log.d("id", Integer.toString(id));
    final int id1 = c.getInt(c.getColumnIndex(Contactsnew.userId1));
    Log.d("id1", Integer.toString(id1));
    final int id2 = c.getInt(c.getColumnIndex(Contactsnew.listId));
    Log.d("id2", Integer.toString(id2));
    final String content = c.getString(c.getColumnIndex(Contactsnew.CONTENT));
    Log.d("co", content);
    final int checkbox = c.getInt(c.getColumnIndex(Contactsnew.ITEMREMINDER));
    Log.d("checkn", Integer.toString(checkbox));
    String valcheck = Integer.toString(checkbox);
     tcontent = (TextView)view.findViewById(R.id.content123);
       tcontent.setText(content);

   check = (CheckBox)view.findViewById(R.id.itemcheck);
    if(checkbox == 1){
        ImageView iv = (ImageView) view.findViewById(R.id.photo1234);
        iv.setImageResource(R.drawable.cancel);
        check.setChecked(true);
        tcontent.setPaintFlags(tcontent.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

    }else if(checkbox == 0){
        ImageView iv = (ImageView) view.findViewById(R.id.photo1234);
        iv.setImageResource(R.drawable.remind);
        check.setChecked(false);
        tcontent.setPaintFlags(tcontent.getPaintFlags() & ~ Paint.STRIKE_THRU_TEXT_FLAG);

    }
       TextView text1 = (TextView)view.findViewById(R.id.editviewcon);
       RelativeLayout layout = (RelativeLayout)view.findViewById(R.id.linear123);
        if (col % 2 != 1) {
            layout.setBackgroundColor(0xFFC1E7FF);
        } else {
            layout.setBackgroundColor(0xFF98D4FA);
        }
        col++;
        LinearLayout layou1 = (LinearLayout) view.findViewById(R.id.linearali11);
        if (col1 % 2 != 1) {
            layou1.setBackgroundColor(0xFF87CEFA);
        } else {
            layou1.setBackgroundColor(0xFF6495ED);
        }
        col1++;
       final TextView ttext = (TextView)view.findViewById(R.id.finaltext);
        final LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll11);


       final SQLiteConnectornew sqlCon = new SQLiteConnectornew(context);
       check.setOnCheckedChangeListener(new OnCheckedChangeListener()
        {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                if (check.isChecked() )
                {
                    // perform logic
                    itemreminder = true;
                    sqlCon.updatable1(itemreminder, id, id1);
                    tcontent.setPaintFlags(tcontent.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                }
                else {
                    itemreminder = false;
                    sqlCon.updatable1(itemreminder, id, id1);
                    tcontent.setPaintFlags(tcontent.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
                }
            }
        });

        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (!Alertadditem.clicked) {
                    //_id1 = GetSet.getUserId();
                    Intent intent = new Intent(context, Alertedit.class)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("id", id);
                    intent.putExtra("id1", id1);
                    intent.putExtra("id2", id2);
                    Log.d("id", "reacged2");
                    intent.putExtra("content", content);
                    context.startActivity(intent);
                }
4

1 回答 1

1

您不能对所有 5 个列表项使用删除线文本,因为在 bindview 方法中,如果您将项目添加到列表视图,它将获取您插入的最后一个项目的视图。所以你可以只删除最后一项的文本!!克服的最好方法是在你的主类中使用 custadapter 并找到列表视图,设置 onclicklistener 并尝试在该视图下使用那些删除线!!

于 2013-09-04T14:11:30.953 回答