I have source code for a slider puzzle. it delivers a random image for the puzzle and you can change alot of settings like tiles and numbers and what not. Its really easy to add pictures you just have to have them start with image_ and put them in the drawable folder. Only thing is it does not have a layout.xml i guess everything is written through the activity.
I want to have all of the pictures in like a gallery view when a button is clicked in the menu. i have seen all the gallery codes need code in the layout which this source code does not have so essentially i would like
rather than this
public void showAbout()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.title_about);
builder.setMessage(R.string.content_about);
builder.setPositiveButton(R.string.label_ok, null);
builder.setIcon(R.drawable.ic_launcher);
AlertDialog dlg = builder.create();
dlg.show();
((TextView) dlg.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}
i just want it to show up as a photo gallery
Related
I have loaded a webview by default, with settings and url at the bottom of the page, i need to display that existing webview in an alert dialog box.
I don't want to create new webview since i need to maintain the state of the existing webview (i mean if i had clicked on the button inside the webivew and toggled the content, then i need to show the exact same content in alert dialog)
I tried to inflate by moving the webview along with some textview in seperate layout but it on alert dialog it shows textview but webview is not loaded.
Suggestions welcome!!
To be clear, i assume your question is to reuse an existing web view from a layout and display it in alert dialog box.
If so you can remove web view from the original layout and add it in alert dialog as follows
WebView myWebview = findViewById(R.id.myWebView);
ViewGroup parent = (ViewGroup) myWebview.getParent();
if (parent != null) {
parent.removeView(myWebview);
}
AlertDialog.Builder builder;
AlertDialog alert;
builder = new AlertDialog.Builder(this);
alert = builder.create();
alert.setView(myWebview);
alert.show();
so the existing webview will be removed from its layout and displayed on the alert dialog.
You can also do the vice versa (remove webview from alert dialog and append in the previous layout.
I'm trying to open up a pop-up window with 4 buttons on it that will dismiss when a button is pressed or when the user clicks outside of the pop-up window. I would just make an alert dialogue, but that will only support 3 buttons.
There have been a lot of questions about this same thing, and I can't find any consistent answer or any answer that works for me (including the deprecated Bitmap Drawable). I've put all of the suggestions I've seen into my code, but to no avail.
Here's everything I've used so far:
//to create new popup window
LayoutInflater chooseMealInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View chooseMealLayout = chooseMealInflater.inflate(R.layout.choose_meal_dialog, null);
PopupWindow chooseMealPopup = new PopupWindow(chooseMealLayout, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
//to make popup dismiss on touch outside
chooseMealPopup.setOutsideTouchable(true);
chooseMealPopup.setFocusable(true);
chooseMealPopup.setContentView(chooseMealLayout);
chooseMealPopup.showAtLocation (chooseMealLayout, Gravity.CENTER,0,0);
chooseMealPopup.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
I've tried to find everything I can, like keeping setFocusable before showAtLocation, but when I run the app, nothing happens when I click. Figured it might be something individual to my code, since I'm new and don't really know what I'm doing.
don't know what you really want to do...
if you want show dialog when click button
YourBtn.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
//what you want to do like show dialog
}
});
In my app, I have a dialog with EditText. I have coded it in such a way that as soon as the dialog shows up,the soft keyboard shows up, the edit text will get focus , all the existing text in the editText is preselected. And user can start typing. This all works fine when I am holding my phone in portrait orientation. But the same thing does not work when I have phone in landscape orientation. Part of my code in my fragment is pasted below.
final EditText inputDeviceId = new EditText(getActivity());
inputDeviceId.setInputType(InputType.TYPE_CLASS_TEXT);
String savedDevId = getDeviceID();
inputDeviceId.setText(savedDevId);
inputDeviceId.setSelectAllOnFocus(true);
// some more code ... to create dialog , ok cancel buttons then,
final AlertDialog alertDialog = alertDialogBuilder.create();
inputDeviceId.setOnFocusChangeListener(new View.OnFocusChangeListener() {
if(hasFocus){
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
});
alertDialog.show();
Now this all works in portrait orientation and does not work in landscape.
In landscape mode the dialog with edittext shows up , it has focus and existing text is preselected but it does not show the keyboard. User has to click in the editText for keyboard to come up. Why? I am using nexus-5 to test.
I have a lot of images in the assets folder of my application that I'd like to display in a dialog popup. How can I go about doing this? I saw a similar question covering how to display the icons, with a pretty solid answer. But in the answer, the icons are pulled from a drawable. So, I suppose I have two options:
I have taken a look at the "Icons in a list dialog" thread but the answer posted uses drawables. I don't have a drawable for every single image because I have over 250 images.
Then I saw the "load drawable from assets" thread, but that doesn't quite get me there either. The "icons in a list dialog" expects a specific r.drawable.drawablename.
This is currently how I display the countries text:
public void onClick(Card card, View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(FtC_Setup.this);
builder.setTitle("Standard countries");
final CharSequence[] items = FtC_Play.allCountries.toArray(new CharSequence[FtC_Play.allCountries.size()]);
builder.setItems(items, null).show();
}
Is it possible to make the background behind an AlertDialog opaque or black without using a Dialog / CustomDialog, I currently have this,
<item name="android:backgroundDimEnabled">true</item>
in my style which I assign to the constructor of the AlertDialog. but it is not dark enough and users can still see information which I do not want them to yet. To be honest my reason for not wanting to use a Dialog is that I have already got everything working with the AlertDialog and thought it would be a good idea to check if anyone knew a quick way to do this.
private void dimActivity(Dialog dialog, float dimAmount) {
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount = dimAmount;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
dimAmount: 0 - no dimming, 1.0f full dimming. You can check this: How to dim a screen on click of a button in android?
use this code this might help you
final Dialog dialog = new Dialog(context);
Window window = dialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);