Question

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. The strikethrough text is working only for the last checkbox. May i know why this problem occurs in 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);
                }
Was it helpful?

Solution

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. 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!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top