简体   繁体   English

复选框条件下的删除线textview Android?

[英]Strikethrough textview under checkbox conditions Android?

In my application i have a customlistview with textview and checkbox the values are called from bindview.My problem is if i add 5 list to the view. 在我的应用程序中,我有一个带文本视图和复选框的customlistview值是从bindview调用的。我的问题是如果我在视图中添加5个列表。 The strikethrough text is working only for the last checkbox. 删除线文本仅适用于最后一个复选框。 May i know why this problem occurs in bindview. 我可以知道为什么在bindview中发生此问题。 Thanks in advance. 提前致谢。

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);
                }

You can't use the strikethroughtext for all the 5 listitems, coz in a bindview method if u add items to your listview it ll take the view of the last item which you inserted. 您不能对所有5个列表项都使用删除线文本,如果您将项目添加到列表视图中,它将采用您插入的最后一个项目的视图,所以在bindview方法中不能使用删除线文本。 So u can strike through the text only for the last item!!The best way to overcome is use custadapter in your mainclass and find the listview, set onclicklistener and try using those strikethrough under that view!! 因此,您只能删除最后一项的文本!最好的克服方法是在您的主类中使用custadapter并找到列表视图,设置onclicklistener并尝试在该视图下使用这些删除线!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM