I have the below code:
// If CheckBox is toggled, update the planet it is tagged with.
checkBox.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v ;
Planet planet = (Planet) cb.getTag();
planet.setChecked( cb.isChecked() );
**ArrayList<String> FavList = new ArrayList<String>();
FavList.add(planet.name);**
}
});
public void test (View view){
Intent myintent = new Intent (getApplicationContext(), MultipleItemsList.class);
myintent.putExtra("name", FavList);
startActivity(myintent);
}
}
What I want to do is add the checked planets to the “FavList” and then populate the list when a button is clicked. The method test is joined to a button, but I am getting the error FavList cannot be resolved to a variable
1. You have declared and initialized the
FavListinside theAnonymous Inner Classscope.2.
Declare and Initializeit atOuter Classscope, and to use it in the Inner class.3. And if you are Declaring and Initializing it in the method, make it
final, so there can be an access to it from Inner class.