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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:45:12+00:00 2026-05-22T15:45:12+00:00

i’ve placed a button on my dialog layout that i would like to trigger

  • 0

i’ve placed a button on my dialog layout that i would like to trigger a complete redraw of the Dialog. However, it appears you can’t open dialogs from within onCreateDialog, and i can’t find a way to dismiss dialogs without using setPositiveButton and the like, as it’s the only Button override that gives the dialog as a parameter (and i can’t find a way to get it for a Button that’s part of the layout). here’s all the relevant code:

case DIALOG_WIFI_PREF:
{
    Dialog dialog = new Dialog(this);
    final View dialogLayout = inflater.inflate(R.layout.dialog_wifi_pref, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dialogLayout);
    builder.setTitle("IP Configuration");
    final EditText ipIn = (EditText)dialogLayout.findViewById(R.id.wifi_ip_in);
    final EditText portIn = (EditText)dialogLayout.findViewById(R.id.wifi_port_in);
    final EditText labelIn = (EditText)dialogLayout.findViewById(R.id.site_label_in);
    final EditText codeIn = (EditText)dialogLayout.findViewById(R.id.activation_code);
    final Spinner siteSpn = (Spinner)dialogLayout.findViewById(R.id.site_spn);
    final Button deleteBtn = (Button)dialogLayout.findViewById(R.id.delete_btn);

    final Cursor cur = mDb.rawQuery("SELECT * FROM " + DbSchema.SiteSchema.TABLE_NAME, null);
    cur.moveToFirst();

    final SimpleCursorAdapter tempAdapter = new SimpleCursorAdapter(
        this,
        android.R.layout.simple_spinner_item,
        cur,
        new String[] { DbSchema.SiteSchema.COLUMN_LABEL },
        new int[] { android.R.id.text1 }
    );
    tempAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    siteSpn.setAdapter(tempAdapter);

    //fill the initial values
    String initSite = pref.getString("site_id", "New Site");
    String spnLabel = null;
    final Cursor initCur = mDb.query(DbSchema.SiteSchema.TABLE_NAME, null, DbSchema.SiteSchema.COLUMN_LABEL + "=?", new String[] { initSite }, null, null, null);
    initCur.moveToFirst();
    cur.moveToFirst();
    if(initCur.getCount()>0) {
        ipIn.setText(initCur.getString(initCur.getColumnIndex(DbSchema.SiteSchema.COLUMN_IP)));
        portIn.setText(initCur.getString(initCur.getColumnIndex(DbSchema.SiteSchema.COLUMN_PORT)));
        codeIn.setText(initCur.getString(initCur.getColumnIndex(DbSchema.SiteSchema.COLUMN_ACTIVATION_CODE)));
        spnLabel = initCur.getString(initCur.getColumnIndex(DbSchema.SiteSchema.COLUMN_LABEL));
        labelIn.setText(spnLabel);
        if(cur.getCount()>0) {
            do {
                if(spnLabel.equals(cur.getString(cur.getColumnIndex(DbSchema.SiteSchema.COLUMN_LABEL)))) {
                    siteSpn.setSelection(cur.getPosition());
                }
            } while(cur.moveToNext());
        }
    }

    siteSpn.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                cur.moveToFirst();
                if(cur.getCount()>0) {
                    do {
                        String tempLabel = cur.getString(cur.getColumnIndex(DbSchema.SiteSchema.COLUMN_LABEL));
                        if(tempLabel.equals(((TextView)view.findViewById(android.R.id.text1)).getText().toString())) {
                            labelIn.setText(tempLabel);
                            portIn.setText(cur.getString(cur.getColumnIndex(DbSchema.SiteSchema.COLUMN_PORT)));
                            ipIn.setText(cur.getString(cur.getColumnIndex(DbSchema.SiteSchema.COLUMN_IP)));
                            codeIn.setText(cur.getString(cur.getColumnIndex(DbSchema.SiteSchema.COLUMN_ACTIVATION_CODE)));
                        }
                    } while(cur.moveToNext());
                }
            }

            public void onNothingSelected(AdapterView<?> parent) {
                //
            }
        });

    deleteBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //do things
                cur.moveToFirst();
                while(cur.moveToNext()) {
                    String tempLabel = cur.getString(cur.getColumnIndex(DbSchema.SiteSchema.COLUMN_LABEL));
                    View selectedSiteView = siteSpn.getSelectedView();
                    String label = ((TextView)selectedSiteView.findViewById(android.R.id.text1)).getText().toString();
                    if(tempLabel.equals(label)) {
                        mDb.delete(DbSchema.SiteSchema.TABLE_NAME, DbSchema.SiteSchema.COLUMN_LABEL+"=?", new String[] { label });
                        //dialogLayout.invalidate();
                        //dialog.dismiss();
                        //dialog.invalidate();
                        //v.getParent().invalidate();
                    }
                }
            }
        });

    builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                cur.moveToFirst();
                boolean newRecord = true;
                do {
                    String tempLabel = null;
                    if(cur.getCount()>0) {
                        tempLabel = cur.getString(cur.getColumnIndex(DbSchema.SiteSchema.COLUMN_LABEL));
                    }
                    if(tempLabel!=null && tempLabel.equals(labelIn.getText().toString())) {
                        //update
                        ContentValues cv = new ContentValues();
                        cv.put(DbSchema.SiteSchema.COLUMN_IP, ipIn.getText().toString());
                        cv.put(DbSchema.SiteSchema.COLUMN_PORT, portIn.getText().toString());
                        cv.put(DbSchema.SiteSchema.COLUMN_ACTIVATION_CODE, codeIn.getText().toString());
                        MobileDashboardActivity.this.mDb.update(DbSchema.SiteSchema.TABLE_NAME, cv, DbSchema.SiteSchema.COLUMN_LABEL+"=?", new String[] { tempLabel });
                        newRecord = false;
                        break;
                    }
                } while(cur.moveToNext());
                if(newRecord) {
                    //new entry
                    ContentValues cv = new ContentValues();
                    cv.put(DbSchema.SiteSchema.COLUMN_IP, ipIn.getText().toString());
                    cv.put(DbSchema.SiteSchema.COLUMN_PORT, portIn.getText().toString());
                    cv.put(DbSchema.SiteSchema.COLUMN_LABEL, labelIn.getText().toString());
                    cv.put(DbSchema.SiteSchema.COLUMN_ACTIVATION_CODE, codeIn.getText().toString());
                    MobileDashboardActivity.this.mDb.insert(DbSchema.SiteSchema.TABLE_NAME, null, cv);
                }
                SharedPreferences.Editor editor = pref.edit();
                editor.putString("site_id", labelIn.getText().toString());
                editor.putString("activation", codeIn.getText().toString());
                editor.commit();
                MobileDashboardActivity.this.writeCSVFile("dashboard_settings.csv");
                dialog.dismiss();
            }
        });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
    dialog = builder.create();
    return dialog;
}
  • 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-22T15:45:13+00:00Added an answer on May 22, 2026 at 3:45 pm

    i ended up following this example:

    http://developmentality.wordpress.com/2009/10/31/android-dialog-box-tutorial/

    which uses the Command pattern to proc outer logic:

    http://en.wikipedia.org/wiki/Command_pattern

    and here are the files:

    Command.java:

    package com.conceptualsystems.dialog;
    
    [...import statements...]
    
    public interface Command {
        public void execute();
    
        public static final Command NO_OP = new Command() { public void execute() {} };
    }
    

    CommandWrapper.java:

    package com.conceptualsystems.dialog;
    
    [...import statements...]
    
    public class CommandWrapper implements DialogInterface.OnClickListener {
        private Command command;
        public CommandWrapper(Command command) {
            this.command = command;
        }
    
        public void execute() {
            command.execute();
        }
    
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            command.execute();
        }
    }
    

    relevant code from MainActivity.java (member variable definition):

    Command delete = new Command() {
            public void execute() {
                removeDialog(DIALOG_WIFI_PREF);
                showDialog(DIALOG_WIFI_PREF);
            }
        };
    

    dialog code utilizing Command class and CommandWrapper:

    builder.setNeutralButton("Delete", new CommandWrapper(delete) {
        public void onClick(DialogInterface dialog, int which) {
            //do things
            cur.moveToFirst();
            while(cur.moveToNext()) {
                String tempLabel = cur.getString(cur.getColumnIndex(DbSchema.SiteSchema.COLUMN_LABEL));
                View selectedSiteView = siteSpn.getSelectedView();
                String label = ((TextView)selectedSiteView.findViewById(android.R.id.text1)).getText().toString();
                if(tempLabel.equals(label)) {
                    mDb.delete(DbSchema.SiteSchema.TABLE_NAME, DbSchema.SiteSchema.COLUMN_LABEL+"=?", new String[] { label });
                }
            }
            dialog.dismiss();
            this.execute();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.