I have some Android code, where I'm using Dialog class to display
public void createCustomDialog(String msg)
{
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Error");
dialog.setCancelable(true);
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText(msg);
ImageView img = (ImageView) dialog.findViewById(R.id.image);
img.setImageResource(android.R.drawable.ic_dialog_alert);
dialog.show();
}
Can anyone help me with the corresponding Blackberry code for it
You can use the BlackBerry Dialog class to do this.
You would use this:
Dialog.alert(String message);
as follows:
Dialog.alert.("This is a Dialog!");
Output (In a Dialog Box):
This is a Dialog!
To add Image Please see :
http://www.javaquery.com/2011/07/how-to-put-image-in-dialog-box.html
Related
I am trying to show a showcase inside my bottomsheetdialog, as shown in my code below:
MainActivity.java:
report.setOnClickListener(v -> {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.bottom_dialog_layout);
EditText report_bill_type = dialog.findViewById(R.id.bll);
dialog.show();
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable((Color.TRANSPARENT)));
dialog.getWindow().setGravity(Gravity.BOTTOM);
new GuideView.Builder(v.getContext())
.setTitle("Title here")
.setContentText("Description here")
.setGravity(smartdevelop.ir.eram.showcaseviewlib.config.Gravity.auto)
.setTargetView(report_bill_type) //showcase keeps showing behind the dialog
.setDismissType(DismissType.anywhere)
.build()
.show();
});
When I execute the code, the showcase keeps showing behind the dialog. How do I resolve this issue?
I am using this showcase view.
I am trying to display a custom Alert Dialog in a fragment. The name of my fragment is MoviesFragFragmentActivity.java
Here is my code:
final AlertDialog dialog1 = new AlertDialog.Builder(MoviesFragFragmentActivity.this).create();
View inflate = getLayoutInflater().inflate(R.layout.custom3,null);
dialog1.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog1.setView(inflate);
TextView t1 = (TextView) inflate.findViewById(R.id.t1);
TextView t2 = (TextView) inflate.findViewById(R.id.t2);
TextView t3 = (TextView) inflate.findViewById(R.id.t3);
LinearLayout b1 = (LinearLayout) inflate.findViewById(R.id.b1);
ImageView i1 = (ImageView) inflate.findViewById(R.id.i1);
LinearLayout bg = (LinearLayout) inflate.findViewById(R.id.bg);
t1.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/en_medium.ttf"), 0);
t2.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/sansation_regular.ttf"), 0);
t3.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/sansation_regular.ttf"), 0);
i1.setImageResource(R.drawable.splash);
i1.getDrawable().setColorFilter(Color.parseColor("#008DCD"), PorterDuff.Mode.SRC_IN);
t1.setText("Oh,No...");
t2.setText("This feature is not available yet, try after new update ");
t3.setText("Try again");
_rippleRoundStroke(bg, "#FAFAFA", "#000000", 40, 0, "#000000");
_CardView(b1, 10, 100, "#008DCD", true);
b1.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){
// Default item selected on bottom navigation onCreate
bottomnavigation4.getMenu().findItem(2).setChecked(true);
SketchwareUtil.showMessage(getApplicationContext(), "Try again later");
dialog1.dismiss();
}
});
dialog1.setCancelable(false);
dialog1.show();
On compilation, it gives me this error:
ERROR in /storage/emulated/0/.sketchware/mysc/680/app/src/main/java/com/liquidapps/movieapp/MoviesFragFragmentActivity.java (at line 601)
final AlertDialog dialog1 = new AlertDialog.Builder(MoviesFragFragmentActivity.this).create();
The constructor AlertDialog.Builder(MoviesFragFragmentActivity) is undefined
How does I display my alert dialog in my Fragment?
I tried using the same code in an activity (Main activity.java) and it works fine, but once I use the code in a fragment, I receive the error.
Use getActivity() instead of MoviesFragFragmentActivity.this
I have some codes like this:
ArrayList<Teacher> teachers = subs.get(position).getTeachers();
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
View v = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_layout, null);
builder.setView(v);
ListView listViewDialog = (ListView) v.findViewById(R.id.dialog_lv);
TesAdapter adapter1 = new TesAdapter(MainActivity.this, teachers);
listViewDialog.setAdapter(adapter1);
adapter1.notifyDataSetChanged();
listViewDialog.setDivider(null);
builder.show();
This operation takes a lot of time. So, I am trying to show a ProgressDialog while it is loading. then to hide the progressbar and show this AlertDialog.
I have tried these:
How to show progress dialog in Android?
How can I run code on a background thread on Android?
But none of them worked :( any solution?
// Custom Dialog Box
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this, R.style.Theme_AppCompat_Dialog_Alert);
final View mView = getLayoutInflater().inflate(R.layout.completed, null);
ImageButton imgForm = (ImageButton) mView.findViewById(R.id.RateButton);
mBuilder.setCancelable(false);
mBuilder.setView(mView);
final AlertDialog dialog = mBuilder.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show(); // Dialogbox appears
// Interest Rating
final AlertDialog.Builder nBuilder = new AlertDialog.Builder( MainActivity.this, R.style.Theme_AppCompat_Light_Dialog_Alert);
final View nView = getLayoutInflater().inflate(R.layout.intrst, null);
Save_Intrst = (Button) nView.findViewById(R.id.SaveIntrst);
nBuilder.setCancelable(false);
nBuilder.setView(nView);
final AlertDialog dilog = nBuilder.create();
// LongPress Image Button
imgForm.setOnLongClickListener(new View.OnLongClickListener(){
#Override
public boolean onLongClick(View view){
dialog.dismiss();
dilog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dilog.show(); // Dialogbox appears
return true;
}
});
Save_Intrst.setOnClickListener(new View.OnClickListener(){
String IntrstLvl;
#Override
public void onClick(View v){
RatingBar rBar = (RatingBar)nView.findViewById(R.id.ratingStar);
IntrstLvl = Integer.toString(rBar.getNumStars());
addData(IntrstLvl);
dilog.dismiss();
Log.d(TAG,"Dismissed");
}
});
Whenever I select "save" within the Save_Intrst it saves 5 stars regardless of what I choose. I'm still fairly new to Android development and have been java coding for a bit now.
This is just a snippet of code of the project and I believe it will be enough, it shows my submit button, the submit button will launch a dialog box that will have a secret button in an image (ImgForm) the image doesn't show but that's not the problem, after long pressing it will launch another dialog that has a 5 Star Rating Bar and a Save button, this is used for rating after the person completes the previous requirements. The rating will always save "5" regardless of what was inserted, even after a reinstall of app onto the device.
getNumStars() will tell you the maximum number of stars shown and will always be 5 as you have defined it. If you want the actual selected rating, you will need getRating(). See this documentation.
You need to use the rBar.getRating()
RatingBar rBar = (RatingBar)nView.findViewById(R.id.ratingStar);
IntrstLvl = Integer.toString(rBar.getRating());
https://developer.android.com/reference/android/widget/RatingBar.html
You are calling getNumStars() which according to the documentation "Returns the number of stars shown." which means the total number of stars a user can select. You should instead be checking getRating() which returns the number of stars currently selected.
https://developer.android.com/reference/android/widget/RatingBar.html#getRating()
I am taking data from a website and placing inside of a text view so that I can center it using setGravity(Gravity.CENTER). However when i place the text view inside of the alert dialog I can no longer scroll down to see the end of my message. Can someone help me with this problem? Thank You
TextView msg1=new TextView(Welcome.this);
//Takes data from a website
msg1.setText(Html.fromHtml(getText("http://www.cellphonesolutions.net/welcome-en")));
msg1.setGravity(Gravity.CENTER);
LinearLayout dialogLayout = new LinearLayout(Welcome.this);
dialogLayout.addView(msg1);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
AlertDialog welcome = new AlertDialog.Builder(Welcome.this).create();
welcome.setView(dialogLayout);
welcome.setButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//rest of the code....
You can try changing the code like this:
dialogLayout.addView(msg1);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
AlertDialog welcome = new AlertDialog.Builder(Welcome.this).create();
ScrollView scrollPane = new ScrollView(this);
scrollPane.addView(dialogLayout);
welcome.setView(scrollPane);