Example usage for android.app Dialog findViewById

List of usage examples for android.app Dialog findViewById

Introduction

In this page you can find the example usage for android.app Dialog findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:org.mixare.MixListView.java

public void loadStopDetailsDialog(String title, StopMarker stop) {
    Dialog d = new Dialog(this) {
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK)
                this.dismiss();
            return true;
        }/*from   w w  w .j  a  v  a 2s . c  om*/
    };

    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.getWindow().setGravity(Gravity.CENTER);
    d.setContentView(R.layout.stopdetailsdialog);

    TextView titleView = (TextView) d.findViewById(R.id.stopDetailDialogTitle);
    titleView.setText(title);

    ExpandableListView list = (ExpandableListView) d.findViewById(R.id.stopDetailDialogRouteList);

    final Button button = (Button) d.findViewById(R.id.stopWalkRouteButton);
    final double longitude = stop.getLongitude();
    final double latitude = stop.getLatitude();

    final Location start = mixContext.getCurrentLocation();

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent mapIntent = new Intent(org.mixare.maps.HelloGoogleMapsActivity.class.getName());
            mapIntent.putExtra("startLocation", start);
            mapIntent.putExtra("destLat", latitude);
            mapIntent.putExtra("destLong", longitude);

            startActivity(mapIntent);
        }
    });

    List<Map<String, ?>> groupMaps = stop.getRouteList();
    List<List<Map<String, ?>>> childMaps = stop.getRouteSubdataList();

    SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(this, groupMaps,
            R.layout.stopdetailsdialogitemroute, new String[] { "id", "name" },
            new int[] { R.id.routeNumber, R.id.routeName }, childMaps, R.layout.stopdetailsdialogroutevariation,
            new String[] { "direction", "name", "times" },
            new int[] { R.id.routeVariationDirection, R.id.routeVariationName, R.id.routeVariationTimes });

    list.setAdapter(adapter);

    d.show();

    new StopTimesTask(adapter, stop).execute(groupMaps, childMaps);
}

From source file:com.prad.yahooweather.YahooWeatherActivity.java

private void showFacebookshareDialog(String okButotnText) {

    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.dialog_layout);
    dialog.setTitle("Post to Facebook");

    Button dialogButton = (Button) dialog.findViewById(R.id.cancel_dialog);
    // if button is clicked, close the custom dialog
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override//from w w w.j a v  a  2s.  co  m
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    Button postButton = (Button) dialog.findViewById(R.id.post_to_facebook);
    postButton.setText(okButotnText);
    // if button is clicked, close the custom dialog
    postButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickPostStatusUpdate();
            dialog.dismiss();
        }
    });

    dialog.show();

}

From source file:com.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for adding a new TodoItem. Called when plus button is tapped.
 *
 * @param view The plus button that is tapped.
 *///from   w  w w  .jav a 2  s  .  c om
public void addTodo(View view) {

    final Dialog addDialog = new Dialog(this);

    // UI settings for dialog pop-up
    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Add Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    addDialog.setCancelable(true);
    Button add = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send POST request to create TodoItem on Bluemix
    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo);
            final String name = itemToAdd.getText().toString();
            // If text was added, continue with normal operations
            if (!name.isEmpty()) {

                // Create JSON for new TodoItem, id should be 0 for new items
                String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}";

                // Create POST request with the Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.POST);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with new TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + name + " created successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "addTodo failed with error: " + errorMessage);
                    }
                });
            }

            // Close dialog when finished, or if no text was added
            addDialog.dismiss();
        }
    });
}

From source file:su.comp.bk.ui.BkEmuActivity.java

protected void prepareDiskManagerDialog(Dialog dialog) {
    prepareFloppyDriveView(dialog.findViewById(R.id.fdd_layout_a), FloppyDriveIdentifier.A);
    prepareFloppyDriveView(dialog.findViewById(R.id.fdd_layout_b), FloppyDriveIdentifier.B);
    prepareFloppyDriveView(dialog.findViewById(R.id.fdd_layout_c), FloppyDriveIdentifier.C);
    prepareFloppyDriveView(dialog.findViewById(R.id.fdd_layout_d), FloppyDriveIdentifier.D);
}

From source file:com.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for updating the TodoItem name. Called when the list item is tapped.
 *
 * @param view The TodoItem that is tapped.
 *//*from   w  w  w.j  a va2s. co m*/
public void editTodoName(View view) {
    // Gets position in list view of tapped item
    final Integer position = mListView.getPositionForView(view);
    final Dialog editDialog = new Dialog(this);

    // UI settings for dialog pop-up
    editDialog.setContentView(R.layout.add_edit_dialog);
    editDialog.setTitle("Edit Todo");
    TextView textView = (TextView) editDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    editDialog.setCancelable(true);
    EditText currentText = (EditText) editDialog.findViewById(R.id.todo);

    // Get selected TodoItem values
    final String name = mTodoItemList.get(position).text;
    final boolean isDone = mTodoItemList.get(position).isDone;
    final int id = mTodoItemList.get(position).idNumber;
    currentText.setText(name);

    Button editDone = (Button) editDialog.findViewById(R.id.Add);
    editDialog.show();

    // When done is pressed, send PUT request to update TodoItem on Bluemix
    editDone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText editedText = (EditText) editDialog.findViewById(R.id.todo);

            final String updatedName = editedText.getText().toString();

            // If new text is not empty, create JSON with updated info and send PUT request
            if (!updatedName.isEmpty()) {
                String json = "{\"text\":\"" + updatedName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}";

                // Create PUT REST request using Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.PUT);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with updated TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + updatedName + " updated successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "editTodoName failed with error: " + errorMessage);
                    }
                });

            }
            editDialog.dismiss();
        }
    });
}

From source file:com.trukr.shipper.fragment.RequestStatus.java

public void contactalertDialog(final Context ctx, String Title, String Content) {
    final Dialog dialog = new Dialog(ctx, R.style.Dialog);
    dialog.setCancelable(false);/*w w w. j av a2  s. c o m*/
    dialog.setContentView(R.layout.contactalertdialog);
    TextView alertHead = (TextView) dialog.findViewById(R.id.tv_alerthead);
    alertHead.setText(Title);
    TextView alertContent = (TextView) dialog.findViewById(R.id.tv_alertcontent);
    alertContent.setText(Content);
    Button btnDialogOk = (Button) dialog.findViewById(R.id.btn_text);
    Button btnDialogCancel = (Button) dialog.findViewById(R.id.btn_call);
    // if button is clicked, close the custom dialog
    btnDialogOk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
            smsIntent.setData(Uri.parse("sms:" + driverContactValue.toString()));
            startActivity(smsIntent);
            dialog.dismiss();
        }

    });

    btnDialogCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri phoneCall = Uri.parse("tel:" + driverContactValue.toString());
            Intent caller = new Intent(Intent.ACTION_DIAL, phoneCall);
            startActivity(caller);
        }
    });
    dialog.show();
}

From source file:org.wso2.cdm.agent.AuthenticationActivity.java

public void showAgreement(String message, String title) {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.custom_terms_popup);
    dialog.setTitle(CommonUtilities.EULA_TITLE);
    dialog.setCancelable(false);/*from w  ww.  j  ava  2s  . c om*/

    WebView web = (WebView) dialog.findViewById(R.id.webview);
    String html = "<html><body>" + message + "</body></html>";
    String mime = "text/html";
    String encoding = "utf-8";
    web.loadDataWithBaseURL(null, html, mime, encoding, null);

    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
    Button cancelButton = (Button) dialog.findViewById(R.id.dialogButtonCancel);

    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Preference.put(context, getResources().getString(R.string.shared_pref_isagreed), "1");
            dialog.dismiss();
            loadPincodeAcitvity();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            cancelEntry();
        }
    });

    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                return true;
            }
            return false;
        }
    });

    dialog.show();
}

From source file:su.comp.bk.ui.BkEmuActivity.java

protected void prepareAboutDialog(Dialog aboutDialog) {
    TextView perfTextView = (TextView) aboutDialog.findViewById(R.id.about_perf);
    float effectiveClockFrequency = this.computer.getEffectiveClockFrequency();
    perfTextView.setText(getResources().getString(R.string.about_perf, effectiveClockFrequency / 1000f,
            effectiveClockFrequency / this.computer.getClockFrequency() * 100f));
}

From source file:edu.berkeley.boinc.PrefsFragment.java

private void setupSliderDialog(PrefsListItemWrapper item, final Dialog dialog) {
    final PrefsListItemWrapperValue valueWrapper = (PrefsListItemWrapperValue) item;
    dialog.setContentView(R.layout.prefs_layout_dialog_pct);
    TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
    SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar);

    if (valueWrapper.ID == R.string.battery_charge_min_pct_header
            || valueWrapper.ID == R.string.prefs_disk_max_pct_header
            || valueWrapper.ID == R.string.prefs_cpu_time_max_header
            || valueWrapper.ID == R.string.prefs_cpu_other_load_suspension_header
            || valueWrapper.ID == R.string.prefs_memory_max_idle_header) {
        Double seekBarDefault = valueWrapper.status / 10;
        slider.setProgress(seekBarDefault.intValue());
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                final String progressString = NumberFormat.getPercentInstance().format(progress / 10.0);
                TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                sliderProgress.setText(progressString);
            }/*from   w w  w .  jav  a2s  .c o m*/

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, seekBarDefault.intValue(), false);
    } else if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) {
        if (!getHostInfo()) {
            if (Logging.WARNING)
                Log.w(Logging.TAG, "onItemClick missing hostInfo");
            return;
        }
        slider.setMax(hostinfo.p_ncpus <= 1 ? 0 : hostinfo.p_ncpus - 1);
        final int statusValue;
        slider.setProgress((statusValue = valueWrapper.status.intValue()) <= 0 ? 0
                : statusValue - 1 > slider.getMax() ? slider.getMax() : statusValue - 1);
        Log.d(Logging.TAG, String.format("statusValue == %,d", statusValue));
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                final String progressString = NumberFormat.getIntegerInstance()
                        .format(progress <= 0 ? 1 : progress + 1); // do not allow 0 cpus
                TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                sliderProgress.setText(progressString);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, statusValue - 1, false);
    } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) {
        slider.setMax(5);
        slider.setProgress(valueWrapper.status.intValue());
        final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener;
        slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
            public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
                String progressString = NumberFormat.getIntegerInstance().format(progress);
                TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status);
                sliderProgress.setText(progressString);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        onSeekBarChangeListener.onProgressChanged(slider, valueWrapper.status.intValue(), false);
    }

    setupDialogButtons(item, dialog);
}

From source file:com.ijsbrandslob.appirater.Appirater.java

private Dialog buildRatingDialog() {
    final Dialog rateDialog = new Dialog(mContext);
    final Resources res = mContext.getResources();

    CharSequence appname = "unknown";
    try {/*from   w  w  w . ja v a 2  s  . c o m*/
        appname = mContext.getPackageManager().getApplicationLabel(
                mContext.getPackageManager().getApplicationInfo(mContext.getPackageName(), 0));
    } catch (NameNotFoundException ex) { /* Do nothing */
    }

    rateDialog.setTitle(String.format(res.getString(R.string.APPIRATER_MESSAGE_TITLE), appname));
    rateDialog.setContentView(R.layout.appirater);

    TextView messageArea = (TextView) rateDialog.findViewById(R.id.appirater_message_area);
    messageArea.setText(String.format(res.getString(R.string.APPIRATER_MESSAGE), appname));

    Button rateButton = (Button) rateDialog.findViewById(R.id.appirater_rate_button);
    Button remindLaterButton = (Button) rateDialog.findViewById(R.id.appirater_rate_later_button);
    Button cancelButton = (Button) rateDialog.findViewById(R.id.appirater_cancel_button);

    rateButton.setText(String.format(res.getString(R.string.APPIRATER_RATE_BUTTON), appname));

    rateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            rateDialog.dismiss();

            mRatedCurrentVersion = true;
            saveSettings();
            launchPlayStore();
        }
    });

    remindLaterButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mReminderRequestDate = new Date();
            saveSettings();
            rateDialog.dismiss();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mDeclinedToRate = true;
            saveSettings();
            rateDialog.dismiss();
        }
    });
    return rateDialog;
}