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 6826793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:11:23+00:00 2026-05-26T22:11:23+00:00

My App will FC when I press the menu button that will call the

  • 0

My App will FC when I press the menu button that will call the Custom AlertDialog :/

Here is my code. Could somebody could help me out?

package com.winkler.plan;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import android.os.Bundle;
import android.webkit.WebView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class StundenplanActivity extends Activity {
    /** Called when the activity is first created. */

    WebView mWebview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //Webview
        mWebview = (WebView) findViewById(R.id.webView);
        mWebview.getSettings().setJavaScriptEnabled(true);
        mWebview.loadUrl("http://www.google.at");

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)           //Menu Inflater
    {                                                       
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }




    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        switch (item.getItemId()) 
        {
            case R.id.plan:     // Shortcut MenuButton Stundeplan
                {
                    mWebview.loadUrl("http://www.haufen.at/stundenplan/index.php");


                }
                return true;

            case R.id.about:    // Shortcut MenuButton About
                {   

                    AlertDialog.Builder builder;
                    AlertDialog alertDialog;

                    Context mContext = getApplicationContext();
                    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
                    View layout = inflater.inflate(R.layout.custom_dialog,
                                                   (ViewGroup) findViewById(R.id.layout_root));

                    TextView text = (TextView) layout.findViewById(R.id.text);
                    text.setText("Hello, this is a custom dialog!");
                    ImageView image = (ImageView) layout.findViewById(R.id.image);
                    image.setImageResource(R.drawable.image);

                    builder = new AlertDialog.Builder(mContext);
                    builder.setView(layout);
                    alertDialog = builder.create();

                    alertDialog.show();
                }
                return true;

            case R.id.call: // Shortcut MenuButton externe
                {
                    final CharSequence[] items = {"Moodle", "Klassenserver", "2AHEL- Website"};

                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle("Pick a color");
                    builder.setItems(items, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int item) {
                            Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show ();

                }
                return true;

            default:
                return super.onOptionsItemSelected(item);
        }

    }



    public void customToast ()
    {
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.layout_toast,
                                       (ViewGroup) findViewById(R.id.toast_layout_root));

        ImageView image = (ImageView) layout.findViewById(R.id.image);
        image.setImageResource(R.drawable.image);
        TextView text = (TextView) layout.findViewById(R.id.text);
        text.setText("Hallo! ich bin ein Custom Toast");


        Toast toast = new Toast(getApplicationContext());
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(layout);
        toast.show();
    }

}

Here is my XML Code for the dialog:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="10dp"
              >
    <ImageView android:id="@+id/image"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:layout_marginRight="10dp"
               />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#FFF"
              />
</LinearLayout>

Thanks! Oh and the list-dialog will not FC.

  • 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-26T22:11:24+00:00Added an answer on May 26, 2026 at 10:11 pm

    Change line builder = new AlertDialog.Builder(mContext); to builder = new AlertDialog.Builder(this);

    A similar situation: Android: ProgressDialog.show() crashes with getApplicationContext
    More: Dialog throwing "Unable to add window — token null is not for an application” with getApplication() as context

    PS. for others: Context mContext = getApplicationContext();

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

Sidebar

Related Questions

I am working on an app that will use a custom keyboard for text
When developing an app that will listen on a TCP/IP port, how should one
I have an App that will send authenticated emails using System.Net.Mail and System.Net.NetworkCredential my
I have an app that will have entries of both varchar(max) and varbinary(max) data
I'm writing an app that will need to make use of Timer s, but
When i start my app and press stop or pause the android app will
I'm currently developing an app that will allow the user to choose an app
ok so im making a lovely little app for my phone that will let
I have an app which will type text on mouse point; even if that
I'm making an app that has more options than will easily fit into a

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.