Results 1 to 5 of 5
Thread: scoping variable question
- 08-12-2012, 05:54 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 10
- Rep Power
- 0
scoping variable question
If you look at the code...
I've made a class variable to hold the View v passed into the containing onClick override to be able to have it available to the inner dialog's positive button onClick block. Is there a different way to scope this to have it available to the inner block without having to use the class variable? (I hope that makes sense =P)Java Code:exit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SFMainMenu.this.view = v; // end game AlertDialog.Builder builder = new AlertDialog.Builder(SFMainMenu.this); builder.setMessage(R.string.exit_message) .setCancelable(false) .setPositiveButton(R.string.yes_string, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { boolean clean = false; clean = engine.onExit(SFMainMenu.this.view); if(clean) { int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid); } } }) .setNegativeButton(R.string.no_string, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { ; // do nothing } }); builder.show(); } });
- 08-12-2012, 08:32 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Re: scoping variable question
You can use a final variable:
Java Code:final View view = v; // later builder.setPositiveButton(R.string.yes_string, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // use view here } );
- 08-12-2012, 09:24 AM #3
- 08-12-2012, 02:03 PM #4
Member
- Join Date
- Aug 2012
- Posts
- 10
- Rep Power
- 0
Re: scoping variable question
db, it's running on android but since I was asking java specific, I figured this would be the right place. pbrockway2, thanks for the help kiwi =)
- 08-12-2012, 03:38 PM #5
Similar Threads
-
Assigning values to a variable (simple question, I believe)
By mikehaas763 in forum New To JavaReplies: 3Last Post: 05-04-2012, 07:46 AM -
Question about Variable Scope
By Solarsonic in forum New To JavaReplies: 2Last Post: 03-17-2011, 06:15 AM -
Elementary question on variable references
By Shayke_ in forum New To JavaReplies: 1Last Post: 02-09-2011, 04:35 PM -
How to select Initial Web Configuration to effect the scoping of beans at the request
By Java Tip in forum Java TipReplies: 0Last Post: 03-31-2008, 10:06 AM -
How to select Initial Web Configuration to effect the scoping of beans at the request
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks