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

  • SEARCH
  • Home
  • 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 8209437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:43:14+00:00 2026-06-07T09:43:14+00:00

I just making a class thats supposed to be a simple Do you want

  • 0

I just making a class thats supposed to be a simple “Do you want to exit?” dialog for each of my activites in my application, and i have some questions. Im a beginner with OOP so dont be mad.

So this is my ExitDialog class:

public class ExitDialog extends Dialog implements OnClickListener
{

private Button dialogOk;
private Button dialogCancel;
private TextView dialogText;

public ExitDialog(Context context)
{
    super(context);

    final Dialog dialog = new Dialog(context, R.style.DialogAnim);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.exitdialog);

    dialogOk = (Button)dialog.findViewById(R.id.dialogOk);
    dialogCancel = (Button)dialog.findViewById(R.id.dialogCancel);
    dialogText = (TextView)dialog.findViewById(R.id.dialogText);


    //How to reach any reference from R.java ?
    //                    
    //dialogOk.setText(getString(R.string.Yes));
    //ialogText.setText(getString(R.string.Exit));


    dialogOk.setOnClickListener(this);
    dialogCancel.setOnClickListener(this);

    dialog.show();
}

@Override
public void onClick(View v)
{


//Many people said on answers, that i must use **getId()** to compare
//these two views, but i can do just like this, bacause i got the message in logcat!
//but the dismiss() just not get called...
    if(v == dialogOk)
    {
        Log.i("ExitDialog", "dialogOk clicked");
        this.dismiss();

    }

}


}

I have 3 questions for you:

How can i reach my application’s R.java file for String references?
As you see i commented out the getString(R.string.Yes) and getString(R.string.Exit) functions because i cannot use it in this outer class.
Any suggestions about who can i do this?

Second question is about .dismiss(). If i call this.dismiss(), my dialog just dont go away it is stays on screen, why is it occurs? How to dismiss then?

Third question is: How to get the parent activity from this outer dialog class? I need it to call .finish() on it, so my app can exit.

Any suggestions will be greatly appreciated.
Thanks.

  • 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-06-07T09:43:16+00:00Added an answer on June 7, 2026 at 9:43 am

    Don’t extend your activity by Dialog,extend it by activity.Call your dialog activity like u call normal activity.But in manifest file add below line under your dialog activity:

    android:theme="@android:style/Theme.Dialog"
    

    and this above setcontentView of activity:

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    You will be able to call Resource and dismiss() function normally as you do for rest of the activities.

    button.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
                    Intent intent=new Intent(YourActivityName.this,DialogClass.class);
                    startActivity(intent);
    
                }
            });
    

    Dialog Activity:

    public class DialogClass extends Activity{
        Button button;
        TextView textView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.custom);
    
            button=(Button) findViewById(R.id.cancel);//belongs to xml file
            button.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
                    finish();
                }
            });
    
            textView=(TextView) findViewById(R.id.ttt);////belongs to xml file
            textView.setText(R.string.app_name);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was making a simple class for a small project and decided to just
Okay, I think I'm just making a stupid mistake here, but I want to
I have a bizarre problem at the moment, I am just making a start
I have a web application that has been running just fine in Internet Explorer
Or: How to expand the sensitive area for a UIControl without just making the
I'm a largely self-taught front-end developer only just making the transition into back-end development
I am not overly competent in C++ and this compiler error is just making
I'm trying to implement paging in a custom ListAdapter. Right now I'm just making
I just started making a database for my website so I am re-reading Database
I've recently been learning the MVVM pattern in WPF and just started making my

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.