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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:31:38+00:00 2026-06-11T18:31:38+00:00

UPDATE: Something must’ve been wrong with Eclipse, since I didn’t get any logged errors

  • 0

UPDATE: Something must’ve been wrong with Eclipse, since I didn’t get any logged errors on the crash. I not get this error when the app crashes as described:

The specified child already has a parent. You must call removeView() on the child's 
parent first.

This occurs when running the noteview.show() method the second time.


Original post

I have a problem with an AlertDialog, which is started from inside the listener of another AlertDialog.

Here’s the code for creating the dialogs and the listener and show() of the dialog(s):

AlertDialog.Builder mdialog;
ArrayAdapter<String> popmenu;
EditText input;

mdialog = new AlertDialog.Builder(ShoppingListApp03Activity.this);
popmenu  = new ArrayAdapter<String>(ShoppingListApp03Activity.this,
           android.R.layout.select_dialog_item);
popmenu.add("Notes");
popmenu.add("Remove");
noteview = new AlertDialog.Builder(ShoppingListApp03Activity.this)
noteview.setTitle("Notes");
input = new EditText(this);
noteview.setView(input);

lv.setOnItemLongClickListener(new OnItemLongClickListener() {
   @Override
       public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
                                                     long id) {
           final String sitem = items.get(position).getId();
           mdialog.setAdapter(popmenu, new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int item) {
                 if (item == 0) {
                    updateFooter("Not implemented. (" + sitem + ")");
                noteview.show();
                 } else {
                    deleteitem = Integer.parseInt(sitem);
                    rmvdialog.show();
                 }
              }
           });

           mdialog.show();
           return false;
        }
     });

/* Click listener for the "Notes" popup menu: */
noteview.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
        Editable value = input.getText();
        // Do something with value!
    }
});
noteview.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
        // Canceled.
    }
});

The onItemLongClickListener opens a popup menu which presents two choices.

The second, which starts rmvdialog(), does its job well. No problems there.

The first, which opens the notes dialog, has a problem: On the first access, it opens the notes dialog and presents the message and the OK and Cancel buttons. However, after returning to the list (main view), either by clicking OK or Cancel in the notes dialog (since neither does anything yet), a second long click and selection of the notes dialog crashes the application.

The crash is without error logging. A try-catch around noteview.show() doesn’t reveal anything either.

I am going blind looking at my own code, so there’s probably something rotten in the design, but I can’t see what.

The overall functionality here is a list with several items. When long-clicking on one of the items, a popup menu with two entries shows. Then, when long-clicking on the one called “notes”, a dialog for showing/editing text, for the item in the list, is presented.

  • 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-11T18:31:39+00:00Added an answer on June 11, 2026 at 6:31 pm

    As you too just found out the same I did. Here is my test activity which I requested from you. As you can see it is a stripped down version of yours (except I use onclick instead of onlongclick)

    public class MainActivity extends Activity {
    
        private Builder firstDialogBuilder;
        private AlertDialog firstDialog;
        private Builder secondDialogBuilder;
        private AlertDialog secondDialog;
        private ListView secondListView;
        private ListView firstListView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            firstDialogBuilder = new AlertDialog.Builder(this);
            firstListView = new ListView(this);
            firstListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] {"First Item1", "First Item2"}));
            firstDialogBuilder.setView(firstListView);
            firstListView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    secondListView = new ListView(MainActivity.this);
                    secondListView.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, new String[] {"Second Item1", "Second Item2"}));
                    secondDialogBuilder.setView(secondListView);
                    secondDialog = secondDialogBuilder.create();
                    secondDialog.show();
                }
            });
    
            secondDialogBuilder = new AlertDialog.Builder(this);
            secondListView = new ListView(this);
            secondListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] {"Second Item1", "Second Item2"}));
            secondDialogBuilder.setView(secondListView);
    
            secondDialogBuilder.setPositiveButton("ok", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(getApplicationContext(), "ok on second", Toast.LENGTH_SHORT).show();
                    secondDialog.dismiss();
                }
            });
            secondDialogBuilder.setNegativeButton("cancel", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(getApplicationContext(), "cancel on second", Toast.LENGTH_SHORT).show();
                    secondDialog.dismiss();
                }
            });
    
            firstDialog = firstDialogBuilder.create();
            firstDialog.show();
        }
    }
    

    For the next time, please provide something like that to help us helping you 🙂

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

Sidebar

Related Questions

I am trying to update the database to show that something has been uploaded.
I have the doubt regarding when to use the Dispatcher.Invoke to update something on
I mean something like: update table_name set field_1=if(date_add(data_field,interval 30 hour) >= now(),1,0), field_2=if(date_add(data_field,interval 30
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
I found something that works with updating one field at here: http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/ UPDATE person
Assuming that I cannot run something like this with Fabric: run(svn update --password 'password'
Something weird's happening with my Rails app. When I try to send an update
I'm developing an application with an error log when something goes bad. It must
The routing I need is quite simple, I must be missing something there. As
I need a black temporary transparent box that must show something like Loading.... with

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.