Is it possible to popup some window above the mainActivity? - android

I have some listView on my mainActivity - the listView contain names of people.
I want to make some window popup that will contain all 'more info' about someone that was click on him.
I mean that if the user click on some person form this list - i want to popup some window above the mainActivity and show more information about that person that was the one who the user click on him
I can't find a way to create the popup window
( AlertDialog is not what i need .. i need dialog that i can edit fully and set data as i want )

yes it's possible
extend Dialog class and make a custom view
public class MyDialog extends Dialog {
YourParams yourParams;
Context context;
public MyDialog(Context context, YourParams yourParams) {
super(context);
this.context = context;
this.yourParams = yourParams;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_sample);
//
// some code ...
//
}
}
then call it like this
MyDialog dialog = new MyDialog(MainActivity.this,yourParams);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();

To follow material design guidelines, I think you can make use of Bottom Sheets, like here on that middle screen:
There are many libraries that will help you with this, for example https://github.com/Flipboard/bottomsheet

Related

how to show a custom dialog box when an activity start

I want to show a custom dialog box when I start my first activity without using a button. I try to search but I'm not finding the proper solution what I really want to do. Many of them are using onClick Listener to achieve that the scenario. Below image is showing an activity with a dialog box, that's what I'm looking for but without using onClick Listener.
How can we implement without using onClick Listener?
Any code contained in a click listener also works elsewhere in the class (unless you use the view that's clicked)
Create the dialog in onCreate. It will open immediately when the activity is started
In your main Activity oncreate method:
createCustomizeDialog();
now create this method outside of oncreate:
private void createCustomizeDialog() {
final AlertDialog.Builder builder=new AlertDialog.Builder(this);
LayoutInflater inflater = getActivity().getLayoutInflater();
#SuppressLint("InflateParams") final View alertLayout = inflater.inflate(R.layout.customize_dialog, null);
Button submit=(Button)alertLayout.findViewById(R.id.sButton);
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
builder.setView(alertLayout);
alertDialog=builder.create();
//noinspection ConstantConditions
alertDialog.show();
}
Just try this way
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("TADAAAA!").create().show();
}
If you want to show the dialog only for the FIRST launch of this activity, you should put the code for your dialog in onCreate method of this activity, if it should be done for EVERY launch of this activity - then in onStart() method.

How to extend AlertDialog.Builder result?

I need to show an AlertDialog with a ListView and a context menu for the ListView items. I prefer to use AlertDialog.Builder and call setItems(), so the Builder creates a ListView inside the AlertDialog with stylized layout for me. For the stylizing it uses internal Android resources, so I cannot reimplement it in my code.
The problem is that I cannot catch a context menu item click event because of default AlertDialog.onMenuItemSelected() implementation, which does not forward such events to the parent:
public boolean onMenuItemSelected(int featureId, MenuItem item) {
return false;
}
I cannot extend AlertDialog.Builder class and force it to create an instance of my own AlertDialog with onMenuItemSelected() overridden because I need to override AlertDialog.Builder.create() for that. But it uses a private P variable, which is not accessible from a derived class:
public AlertDialog create() {
final AlertDialog dialog = new AlertDialog(P.mContext, mTheme, false);
P.apply(dialog.mAlert);
dialog.setCancelable(P.mCancelable);
if (P.mCancelable) {
dialog.setCanceledOnTouchOutside(true);
}
dialog.setOnCancelListener(P.mOnCancelListener);
if (P.mOnKeyListener != null) {
dialog.setOnKeyListener(P.mOnKeyListener);
}
return dialog;
}
Is there a way to force AlertDialog.Builder to construct a custom AlertDialog (with onMenuItemSelected method overridden)?
I still found no solution for the question, but I found some problems, which makes the solution useless. For Android 2.1, built-in ListView items (android.R.layout.select_dialog_item) are displayed as black text on dark grey background, ListView items are not separated from the dialog message (setMessage()), etc.
I finally switched back to my own AlertDialog with custom layout for ListView and its items (AlertDialog.Builer not used). Context menu events can be easily catched this way.
Luksprog, thanks a lot for your comments. But the main idea was to use as many stylized layouts, as possible. AFAIK, no standard layouts (android.R.layout.*) offer the buttons you mentioned. Also, an item could be removed occasionally with the button. With a context menu, at least two click required to remove an item.

Set title and (title) icon for a custom alert dialog

I don't manage to set a neither a title nor a (title) icon to my custom alert dialog.
My code:
public class AddingFavoriteDialog extends AlertDialog {
private OnAddingFavoriteListener onAddingFavoriteListener;
private Context context;
private GeocodingManager geocodingManager;
private FavoritesActivity favoritesActivity;
public AddingFavoriteDialog(Context context, OnAddingFavoriteListener onAddingFavoriteListener) {
super(context, android.R.style.Theme_Dialog);
this.context = context;
this.onAddingFavoriteListener = onAddingFavoriteListener;
this.geocodingManager = new GeocodingManager(context);
this.favoritesActivity = (FavoritesActivity) context;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adding_favorite_dialog2);
setTitle("MYTITLE");
setIcon(R.drawable.star_gold);
}
What am i doing wrong? I also tried to set it by calling super.setTitle("MYTITLE"); in onCreate() as well as in the constructor.
EDIT: Even setButton(BUTTON_POSITIVE, context.getString(R.string.button_value_OK),
new OnClickListener() {...} seems not to work.
Use setView instead of setContentView, because setContentView replaces everything in the AlertDialog, including the default title bar and icon (and buttons etc.). Instead, setView only replaces the middle part (the message, if you will).
Use LayoutInflater if you need to.
Extending Dialog instead of AlertDialog will fix the problem.

howto fire onCreateContextMenu or howto have a contextMenu without any View

I was wondering if it's possible to have a contextMenu without any view..?
Or any Dialog, acting simply like a contextMenu (a list of clickable items in fact)..?
I can explain: on the first use of the app, a pop-up (ContextMenu) list all option modes.
The actual trick is a button, registered for the ContextMenu and the firing is done by button.performLongClick()...
I don't want to have that button anymore, but I still want the ContextMenu
Any idea?
Thanks in advance,
jo
Is that what you want?:
public class MyActivity extends Activity{
static final int MY_DIALOG_ID = 0;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// Sets the activity layout
setContentView(R.layout.my_activity_layout);
showDialog(MY_DIALOG_ID);
}
#Override
protected Dialog onCreateDialog(int dialogID) {
Dialog d;
switch(dialogID){
case MY_DIALOG_ID:
//CREATE YOUR DIALOG HERE
break;
}
return d;
}
}

Android : how to set context to a view in layout xml?

I am using WebView in an ActivityGroup and it will throw an exception if WebView show Dialog and complain the activity is not valid. But it's okay if I set the context of the WebView to the TOP activity. So I wish to know how to set the context in the layout xml ?
You can use layoutinflater to achieve this:
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.yourLayoutName, null);
this.theSpinner = (Spinner) viewToLoad.findViewById(R.id.Spinny);
this.setContentView(viewToLoad );
Hope that helps. for dialog you can just change context from this to
this.getParent()
So I wish to know how to set the context in the layout xml ?
That's not possible. Though, I have some experience with ActivityGroup, so I know how to solve this problem:
// in your ActivityGroup...
public class YourActivityGroup extends ActivityGroup{
public static YourActivityGroup self;
public YourActivityGroup(){
self = this;
// the rest of your code here
}
}
Then, when you need a context in order to show a dialog or a Toast or whatever, you use YourActivityGroup.self.

Categories

Resources