mardi 3 mai 2016

Checkboxes creating multiple pages instead of consolidating in one activity

So I'm trying to utilize 8 checkboxes and I would like to make it so that I can check up to 3 items and then press a button which will pull up a 2nd activity that compares the info that I've matched to each checkbox. However, with what I've currently written, the moment I check something, it immediately brings up the second activity as opposed to waiting for the user to select multiple checkboxes and then press the next button. I'm pretty sure the problem lies in this area of code, though I may be wrong:

MAIN ACTIVITY:

CheckBox showDetails1 = (CheckBox) getActivity().findViewById(R.id.checkBox1);
            showDetails1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showDetails(1);
                }
            });
            CheckBox showDetails2 = (CheckBox) getActivity().findViewById(R.id.checkBox2);
            showDetails2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showDetails(2);
                }
            });

For the sake of making sure stuff worked I tried to test the next button separately.

Button showDetails = (Button) getActivity().
            findViewById(R.id.compare_button);
    showDetails.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            showDetails(5);

2ND ACTIVITY:

@Override
    public void onActivityCreated(Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        TextView tvModel = (TextView) getActivity().findViewById(R.id.model_holder_1);
        TextView tvColor = (TextView) getActivity().findViewById(R.id.color_holder_1);
        TextView tvSize = (TextView) getActivity().findViewById(R.id.size_holder_1);
        ImageView ivImage = (ImageView) getActivity().findViewById(R.id.imageholder_1);

        //TextView tvModel = (TextView) getActivity().findViewById(R.id.model_holder_2);
        //TextView tvColor = (TextView) getActivity().findViewById(R.id.color_holder_2);
        //TextView tvSize = (TextView) getActivity().findViewById(R.id.size_holder_2);
        //ImageView ivImage = (ImageView) getActivity().findViewById(R.id.imageholder_2);

    //TextView tvModel = (TextView) getActivity().findViewById(R.id.model_holder_3);
    //TextView tvColor = (TextView) getActivity().findViewById(R.id.color_holder_3);
    //TextView tvSize = (TextView) getActivity().findViewById(R.id.size_holder_3);
    //ImageView ivImage = (ImageView) getActivity().findViewById(R.id.imageholder_3);

In the 2nd activity I've crossed out the latter portion since it hadn't been working but I was trying to get the 2nd and third checkboxes from the main activity in their correct positions. Instead it only opens 1 page with the info in the holder_1 position - as opposed to 3 different checkbox data in 3 different holder positions.

I've been staring at how to fix this pair of activities and any help is appreciated!




Aucun commentaire:

Enregistrer un commentaire