Can someone tell me how to implement this in an android app. If you can share code, some reference, or a tutorial. Anything will be helpful
You can inflate your custom layout to popup window.
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext(.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,400,400);
popupWindow.showAtLocation(attachment_button, Gravity.CENTER, 10, 200);
Take custom listview in your layout.
You can do this with Dialog that would show when you click at filter_box.
Just create class MyDialog extends Dialog and place your xml layout the place you need "popup" show.
Related
I am making an activity in which an alertDialog will appear. The dialog will have a view which contains:
Linear layout with two editText (Numeric texts) and then setHeight(wrapContent). You can see below.
Hope you are understanding now what i am doing. Here the view is a xml file which i created and it is not the activity's xml file. Now I want that when a user put the pin in the editText then i can get it and confirm it or whatever i want. But the problem is that i am not getting anything when i call getText(). Here is my code.
LayoutInflater factory = getLayoutInflater();
View view = factory.inflate(R.layout.zalert_pass_enable, null); // zalert_pass.. is the xml file
EditText passInput1 = view.findViewById(R.id.inputPass);
EditText passInput2 = view.findViewById(R.id.inputPassConfirm);
String value = passInput1.getText().toString().trim();
I edited my code to so that you can understand, this is not the actual code but it can easily tell my problem. When i toast the value String then i get nothing. Like there are 0 charaters. But i am putting 4 charaters at least each time. Now i know that the problem is in the process of linking the xml file to inflator.
infalInflater.inflate(R.layout.list_item, parent, false);
See the above line of code. This a well upvoted answer of stackOverflow. which tells us that we should not null the inflator. We should give it parent. But what will be the parent in my case.
You can see the picture and that is my problem and i want a solution for that, please help.
Add this line Dialog dialog = new Dialog(context); after you are inflating view and use it to get edittext object like this
LayoutInflater factory = getLayoutInflater();
View view = factory.inflate(R.layout.zalert_pass_enable, null);
Dialog dialog = new Dialog(context); // add this line
EditText passInput1 = dialog.findViewById(R.id.inputPass);
EditText passInput2 = dialog.findViewById(R.id.inputPassConfirm);
String value = passInput1.getText().toString().trim();
I want to create a alert dialog using a layout which is in a xml. I tried this:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View v = inflater.inflate(R.id.optionsmenu, null);
AlertDialog dialog = builder.setView(v).create();
dialog.show();
It does not work. optionsmenu is the layout that i want to use to create alert dialog. Can i set alert dialog view to this inner layout ?
here is the image's url . You can see the layout that i want to use.
I dont really know how you expect your dialog to look like but you should create it like this:
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.activity_main);
dialog.setTitle("");
//to use a view inside the xml (i.e. a button)
Button button = (Button)dialog.findViewById(R.id.optionsmenu);
dialog.show();
Note that you were trying to inflate not the layout but the view (R.id.optionsmenu) it should have been (R.layout.activity_main)
alertDialog.builder is used to create a dialog without using a xml layout
When I create my custom dialog it looks like this :
but I want it to look like this :
Create a class which extends Dialog and inflate it your layout
public class CustomDialog extends Dialog
{
public CustomDialog (Context context)
{
//use this Theme, or any other theme you like
super(context, android.R.style.Theme_Translucent_NoTitleBar);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.your_layout);
}
}
You can use custom dialog and inflate your designed xml into it.
final Dialog yourDialog=new Dialog(context);
thumbnail_click.setContentView(R.layout.yourlayout);
You can use your own cutom layout for dialog as in the follwing link
Custom dialog
Custom Dialog PoPup
You can always inflate your own custom dialog box layout.
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) findViewById(R.id.dialog_layout_root));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
if you haven't got an answer yet, here is a good toturial: Toturial
You vill need to make your own XML shape-style file, and use the corner function ex:
<corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" />
I have a ListActivity which shows list of items. I prepared another layout for detailed view that contains items' name, address, phone number and image. I want to show these items detailed in a popup window if one is clicked without closing my ListActivity.
How can i do that?
You can use AlertDialog to do this. Look here http://developer.android.com/guide/topics/ui/dialogs.html. And scroll to Creating a Custom Dialog. Example is:
AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
You can use a quickAction like the Twitter app or start a new Activity with android:theme="#android:style/Theme.Dialog" specified in your manifest.
Creating dialogs is described on this page: http://developer.android.com/guide/topics/ui/dialogs.html
In Android, is it possible to customize the header layout (the icon + a text) layout of a dialog? Or can I just set a custom string value of the title text?
Thank you.
It's possible to change the header of the Dialog if you set a custom layout for both the dialog and the header. I've only ever used this method to remove the header entirely, but this ought to work for a custom header:
dialog = new Dialog(context);
Window window = dialog.getWindow();
window.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
dialog.setContentView(R.layout.my_dialog_layout);
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);
This is all a tad more complicated (as you have to setup the dialog's layout as well) but it's easier than subclassing Dialog.
the original Dialog class seems to lack the ability to set an icon, but you can easily extend AlertDialog and set a custom view (the same you would use for your Dialog instance), you just need something like this
class MyDialog extends AlertDialog {
public MyDialog(Context ctx) {
super(ctx);
LayoutInflater factory = LayoutInflater.from(context);
View view = factory.inflate(R.layout.dialog_layout, null);
setView(view);
setTitle("MyTitle");
setIcon(R.drawable.myicon);
}
}