lundi 23 mai 2016

checkbox unchecked and checked when i scroll listview in android

public View getView(final int pos, View child, ViewGroup parent) {

        try {
            if (child == null) {
                child = inflater.inflate(R.layout.daily__report__list__view, null);
            }


            Mark = 1 + pos;

            TextView user = (TextView) child.findViewById(R.id.tvDailyName);
            TextView InTime_ = (TextView) child.findViewById(R.id.tvDailyIn);
            TextView OutTime_ = (TextView) child.findViewById(R.id.tvDailyOut);
            CheckBox verify = (CheckBox) child.findViewById(R.id.cbDailyVerify);
            final Spinner Status = (Spinner) child.findViewById(R.id.DailySpinner);


            status = Status.getSelectedItem().toString();

            String item = getItem(pos).toString();
            child.setTag(item);
            user_Id = item.substring(0, item.indexOf("/"));
            time = item.substring(user_Id.length() + 1);
            time2 = time.substring(0, time.indexOf("/"));
            time3 = time.substring(time.indexOf("/") + 1, time.length());

            Button btnSend = (Button) findViewById(R.id.btnSend);
            btnSend.setOnClickListener(this);


            user.setText(user_Id);
            InTime_.setText(time2);
            OutTime_.setText(time3);
            Status.setTag(item);


            lstData.put(user_Id, user_Id + "/" + time2 + "/" + time3 + "/" + Status.getSelectedItem().toString());
            ListView_Report.add(user_Id);

            Status.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    String main = Status.getTag().toString();

                    String userName = main.substring(0, main.indexOf("/"));
                    String timeIn = main.substring(main.indexOf("/") + 1, main.lastIndexOf("/"));
                    String foodFormatted = main.substring(main.indexOf(timeIn), main.length());
                    String timeOut = foodFormatted.substring(foodFormatted.indexOf("/") + 1, foodFormatted.length());

                    lstData.put(userName, userName + "/" + timeIn + "/" + timeOut + "/" + parent.getSelectedItem().toString());
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

        verify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {

                        y = n++;
                        System.out.println("isCheckedisChecked in :" + y);
                    }
                    if (!isChecked) {
                        y = n--;

                        System.out.println("isCheckedisChecked: out  " + y);
                    }

                }
            });

// lvDailyReport = (ListView) findViewById(R.id.lvDailyReport);

            child.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

// String main = lvDailyReport.getSelectedItem().toString();

                    String main = v.getTag().toString();

                    String userName = main.substring(0, main.indexOf("/"));
                    String timeIn = main.substring(main.indexOf("/") + 1, main.lastIndexOf("/"));
                    String foodFormatted = main.substring(main.indexOf(timeIn), main.length());
                    String timeOut = foodFormatted.substring(foodFormatted.indexOf("/") + 1, foodFormatted.length());


                    Bundle bundle = new Bundle();

                    bundle.putString("date", dateView.getText().toString());
                    bundle.putString("userName", userName);
                    bundle.putString("timeIn", timeIn);
                    bundle.putString("timeOut", timeOut);

                    Intent i = new Intent(DailyAttendanceReport.this, Update_Daily_Report.class);

                    i.putExtras(bundle);

                    startActivity(i);
                }


            });
        } catch (Exception e) {
            e.printStackTrace();
        }

        return child;
    }




Aucun commentaire:

Enregistrer un commentaire