-2

This code is part of a context menu that pops up when a listview is clicked. I am trying to get the user result through whether or not a CheckBox is checked or not. The problem is that the string I am creating cannot be resolved.

Here is the code:

final CheckBox input11 = (CheckBox) textEntryView2.findViewById(R.id.checkBoxResult);

            alert2.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            String blazeIt = lvItems.getItemAtPosition(menuInfo.position).toString();
                            String turntupheho = blazeIt.replace(" --COMPLETE", "");
                            String evenmoreturnt = turntupheho.replace(" --INCOMPLETE", "");

                            if (input11.isChecked()) {
                                String bigbutt = " --COMPLETE";
                            } else {
                                String bigbutt = " -INCOMPLETE";
                            }

                            items.set(menuInfo.position, evenmoreturnt + bigbutt); //Cannot resolve symbol 'bigbutt'
                            itemsAdapter.notifyDataSetChanged();
                            writeItems();

                        }
                    }

            );

EDIT: Sorry simple mistake (forgot to declare String); I'm still learning. Thank you everyone for the quick responses.

Abe
  • 153
  • 1
  • 8

5 Answers5

0

You can try this:

String bigbutt;
if (input11.isChecked()) 
{
    bigbutt = " --COMPLETE";
} else {
    bigbutt = " -INCOMPLETE";
}
Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
0

This is a basic Java question not an android question and a simple effort to look for the answer would yield it.

Regardless, here is the code you need to fix your issue

 final CheckBox input11 = (CheckBox) textEntryView2.findViewById(R.id.checkBoxResult);

        alert2.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        String blazeIt = lvItems.getItemAtPosition(menuInfo.position).toString();
                        String turntupheho = blazeIt.replace(" --COMPLETE", "");
                        String evenmoreturnt = turntupheho.replace(" --INCOMPLETE", "");
                        String bigbutt="";
                        if (input11.isChecked()) {
                            bigbutt = " --COMPLETE";
                        } else {
                            bigbutt = " -INCOMPLETE";
                        }

                        items.set(menuInfo.position, evenmoreturnt + bigbutt); //Cannot resolve symbol 'bigbutt'
                        itemsAdapter.notifyDataSetChanged();
                        writeItems();

                    }
                }

        );

And the reason the string is not being resolved is because you defined bigbutt inside of the if condition, giving it the scope of only the if condition, but then you use it outside the if condition, which is also outside of its scope.

Ali Elgazar
  • 777
  • 2
  • 12
  • 26
0

Check now just declare variable outside condition. Silly mistake.

final CheckBox input11 = (CheckBox) textEntryView2.findViewById(R.id.checkBoxResult);

                alert2.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {

                                String blazeIt = lvItems.getItemAtPosition(menuInfo.position).toString();
                                String turntupheho = blazeIt.replace(" --COMPLETE", "");
                                String evenmoreturnt = turntupheho.replace(" --INCOMPLETE", "");
                                String bigbutt="";
                                if (input11.isChecked()) {
                                    bigbutt = " --COMPLETE";
                                } else {
                                    bigbutt = " -INCOMPLETE";
                                }

                                items.set(menuInfo.position, evenmoreturnt + bigbutt); //Cannot resolve symbol 'bigbutt'
                                itemsAdapter.notifyDataSetChanged();
                                writeItems();

                            }
                        }

                );
zakaiter
  • 439
  • 3
  • 11
0

As Java having scope of local variable within the block so you need to declare outside if block.

final CheckBox input11 = (CheckBox) textEntryView2.findViewById(R.id.checkBoxResult);

    alert2.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    String blazeIt = lvItems.getItemAtPosition(menuInfo.position).toString();
                    String turntupheho = blazeIt.replace(" --COMPLETE", "");
                    String evenmoreturnt = turntupheho.replace(" --INCOMPLETE", "");
                    String bigbutt = ""; // Declaration needs here 

                    if (input11.isChecked()) {
                         bigbutt = " --COMPLETE";
                    } else {
                         bigbutt = " -INCOMPLETE";
                    }

                    items.set(menuInfo.position, evenmoreturnt + bigbutt); //Cannot resolve symbol 'bigbutt'
                    itemsAdapter.notifyDataSetChanged();
                    writeItems();

                }
            }

    );
Suhas Bachewar
  • 1,230
  • 7
  • 21
0

The Problem is of scope of the String variable, Declare bigbutt outside the if/else block.