Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:19:13+00:00 2026-05-25T02:19:13+00:00

I have an AlertDialog , which for some strange reason cannot access a final

  • 0

I have an AlertDialog, which for some strange reason cannot access a final int deptID.
When passing the value to the ConfirmRemoval-function, the value is correct, but when I enter the dialog’s onClick event, the final int is undefined!

I have even tried to change this to a global variable, but still no luck.
Anybody know what is going on?

@Override
public void onCreate(Bundle icicle){
    super.onCreate(icicle);

    this.setContentView(R.layout.generic_list);
    Bundle extras = getIntent().getExtras();
    if (extras == null) {return;}
    this.getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> adv, View v,
                int pos, long id) {
            Cursor cursor = (Cursor)adv.getItemAtPosition(pos);
            int deptID = cursor.getInt(cursor.getColumnIndex("DeptID"));
            ConfirmRemoval(deptID);
            return true; //NOTE! If returning false, the itemClick event will fire
        }
    });
}

private void ConfirmRemoval(final int deptID){
        AlertDialog.Builder bld = new AlertDialog.Builder(this);
        bld.setCancelable(false);
        bld.setTitle(R.string.deptRemove);
        bld.setMessage(R.string.deptRemoveMsg);
        bld.setPositiveButton("OK", new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                Dept.RemoveDept(deptID);
                dialog.dismiss();
                GetDepartments();
            }


        });
        bld.setNegativeButton("Cancel", new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        AlertDialog alert = bld.create();
        alert.show();
}

Thanks,
Runey

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:19:14+00:00Added an answer on May 25, 2026 at 2:19 am

    Instead of

    Dept.RemoveDept(deptID) do

    int deptIDlocal = deptID; Dept.RemoveDept(deptIDlocal)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TextView which I place into an AlertDialog like this: final TextView
I have a dialog which performs some validation (below). Thee problem is, the dialog
I have an AlertDialog in and it's got a button, which, if selected, will
I have a public class which has some common generic functions, like e.g. for
I have a activity which start with a alertdialog when i press back button
I have a simple list view with some check boxes in an alert dialog.
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have written a game (I'll give it the name Gamer) in which I
I have an Activity which looks up data from the web in its onCreate
Hello all i have a simple problem i have a alertDialog and i want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.