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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:16:40+00:00 2026-05-29T10:16:40+00:00

I’m new to Android development, I needed to implement custom dialog plugin similar to

  • 0

I’m new to Android development, I needed to implement custom dialog plugin similar to the one in the ChildBrowser plugin.

While I have managed to implement most of the functionality for this dialog, including JS callback events on certain dialog actions, I was unable to implement sending data from JS back to the dialog while it’s shown.

Scenario is the following: when the dialog’s Spinner is changed, JS callback is being called, JS code performs some processing (access sqlStorage data, etc.) and afterwards I need to update some views of the dialog. My current code (without non-relevant things):

CustomDialogPlugin.java:

public class CustomDialogPlugin extends Plugin {
    @Override
    public PluginResult execute(String action, JSONArray args, String callbackId) {
        PluginResult.Status status = PluginResult.Status.OK;
        String result = "";

        try {
            if (action.equals("show")) {
                result = this.showDialog(args.optJSONObject(0), callbackId);
                // ...
            } else if (action.equals("update")) {
                this.updateData(args.optJSONObject(0));
            }
        } catch(JSONException e) {
            // ...
        }
    }

    // Show the dialog
    public String showDialog(JSONObject options, final String callbackId) {
        if (options != null) {
            // Handle options
        }

        // Create the child dialog in new thread
        Runnable runnable = new Runnable() {

            public void run() {
                mDialog = new Dialog(ctx);
                // Dialog layouts, views and listeners setup
                // ...
                mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
                    @Override
                    public void onItemSelected(AdapterView adapter, View v, int i, long lng) {
                        // ...
                        // Prepare JSON data to send and call a callback
                        sendUpdate(CHANGED_EVENT, obj, true);
                    }

                    @Override
                    public void onNothingSelected(AdapterView adapter) {
                        // ...
                    }
                });
                // ...
                mDialog.show();
            }
        };
        this.ctx.runOnUiThread(runnable);
        return "";
    }

    // Create a new plugin result and send it back to JavaScript
    private void sendUpdate(int eventType, JSONObject obj, boolean keepCallback) {
        if (this.savedCallbackId != null) {
            // ...
            PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
            Result.setKeepCallback(keepCallback);
            this.success(result, this.savedCallbackId);
        }
    }

    // Parse data received from JS and upate dialog
    protected String updateData(JSONObject data) {
        // Here I need to update some views of mDialog
        // Can't access them from here
    }
}

customdialog.js:

var CustomDialog = function() {};
CustomDialog.CHANGED_EVENT = 1;

CustomDialog.prototype.show = function(data) {
    return PhoneGap.exec(this._onEvent, this._onError, 'CustomDialogPlugin', 'show', [data]);
};

CustomDialog.prototype.update = function(data) {
    return PhoneGap.exec(this._onEvent, this._onError, 'CustomDialogPlugin', 'update', [data]);
};

CustomDialog.prototype._onEvent = function(data) {
    if (data.type == CustomDialog.CHANGED_EVENT && typeof window.plugins.CustomDialog.onChange === "function") {
        window.plugins.CustomDialog.onChange(data);
    }
    // ...
};
CustomDialog.prototype._onError = function(data) {
    // ...
};

PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin('customDialog', new CustomDialog());
});

test.html:

// ...
window.plugins.customDialog.onChange = function(data) {
    // ...
    window.plugins.customDialog.update(some_other_data);
}

I’ve tried to create a Handler inside Runnable, and call it to handle message sent from updateData, but apparently I’m doing something wrong.

Maybe I’m over-complicating things and there is an easier way to accomplish data update from JS callback?

Thank you in advance.

  • 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-29T10:16:42+00:00Added an answer on May 29, 2026 at 10:16 am

    OK, here is a solution (using Post) that finally worked for me (parameter of the function/return value are not the same as in my original question, but this is still the function I was asking about):

    protected void updateData(String data) {
        mMyEdit.post(
            new Runnable() {
                public void run() {
                    mMyEdit.setText(data);
                }
            }
    );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.