Android popup with multiple pages - android

I am currently creating a popup window by this code:
View popupView = inflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
popupWindow.setAnimationStyle(R.style.Animation);
LinearLayout linearLayout = popupView.findViewById(R.id.linearLayout1);
linearLayout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
popu = false;
}
});
ImageView imageView = popupView.findViewById(R.id.imageView1);
imageView.setImageResource(drawables[position]);
popupWindow.showAtLocation(imageView, Gravity.CENTER, 0, 0);
popu = true;
However, I want the popup to have multiple pages, like here:
How can I implement a multi-paged popup into my app? can I add a ViewPager into my PopupWindow or I need to switch to a Dialog instead?

Use DialogFragment instead.
https://developer.android.com/reference/android/app/DialogFragment.html
Inside of it you will need a ViewPager with your multiple pages
Add page indicators to make it look similar
You can use a library or TabLayout for the indicators:
How do you create an Android View Pager with a dots indicator?

Related

How to show popupWindow as drop down onClick of a Recyclerview row element?

I have tried using a code that is working fine except when I click on the last or end rows of the recyclerview, the popupWindow opens offscreen. Is there any way to show the popupWindow upSide of the view for end rows of the recyclerview.
Here is the code I am using:
public void showPopup(View v, int _pos) {
LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup_row_appointment_option, null);
popupWindow = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
//TODO do sth here on dismiss
}
});
popupWindow.showAsDropDown(v, v.getScrollX(), v.getScrollY());
tv_view_profile = (TextView) popupView.findViewById(R.id.tv_view_profile);
tv_view_profile.setOnClickListener(this);
}
I would suggest you to go for PopupMenu which accepts AnchorView -> with the use of that we can get the exact position where we want to show popup -> you can pass AnchroView as View (The three dot imageview)
Here is the great example of it :
https://www.javatpoint.com/android-popup-menu-example
And also please use Appcompat version to get Material touch in menu.
Ok with custom layout you can go with your regular flow with minor changes --
popup.showAtLocation(anchorView, Gravity.BOTTOM, 0,
anchorView.getBottom() - 60);
this is just an example for bottom gravity. You can set gravity and margin according to your code.
anchorView = the view where you want to show this popup. Try this and let me know if you have any query.

Unable to show PopUpWindow under specific layout Android

I want to show a PopUpWindow under a LinearLayout after closing soft keyboard when clicking a button.
This is what I looking for
When user click the button,the keyboard hide,then the PopUpWindow show under the LinearLayout(area of the keyboard initially). Like this picture below
I try this code:
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//hide the keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
LinearLayout bottomBar = (LinearLayout)findViewById(R.id.bottomBar);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.popup_window, null);
// create the popup window
int width = LinearLayout.LayoutParams.MATCH_PARENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = true; dismiss it
final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);
// show the popup window
popupWindow.showAtLocation(bottomBar, Gravity.BOTTOM, 0, 0);
}
}
But end up the PopUpWindow show like this:
The LinearLayout which contain the button,going to the bottom of screen when the keyboard is hide,the PopUpWindow show on top of the LinearLayout,so it become invisible.Like the image below:
So how can I get the desire behavior like the 1st picture?PopUpWindow show under the LinearLayout after the keyboard is hide.
Why are you trying to do this with popup window. I would suggest you to keep it simple layout. This layout will contain both the views (the layout with button and the popup layout under it). Just add this layout at the bottom of your screen and set the visibility of popup layout visibility VISIBLE/GONE whenever required. You can add the animation while showing or hiding the popup layout with help of this:
Show/Hide View using Slide Up and Down Animation.

Add View into RecyclerView

I tried to add view into RecyclerView when click to Button in a ViewHolder.
When click to Button in ViewHolder3, a View (view add more) will add and appear like image above.
ViewAddMore will pin there and RecyclerView can scroll normal.
I tried but don't found any solution for my issue;
Have any suggest for my issue?
Please use PopupWindow to show this View.
// get a reference to the already created main layout
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.activity_main_layout);
// inflate the layout of the popup window
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.popup_window, null);
// create the popup window
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = true; // lets taps outside the popup also dismiss it
final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);
// show the popup window
popupWindow.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
// dismiss the popup window when touched
popupView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
popupWindow.dismiss();
return true;
}
});
https://developer.android.com/reference/android/widget/PopupWindow.html
How to make a simple android popup window?
Hope this will help you.

PopupWindow doesn't show

I have a PopupWindow in my app.
That is how I initialize it:
final FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(200, 200));
hashTagsWindow = new PopupWindow(frameLayout, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
hashTagsWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
And that is how I try to show it:
hashTagsWindow.showAsDropDown(binding.hash, 20, 20);
But my PopupWindow doesn't display itself.
What I already tried to solve a problem?:
Wrap .showAsDropDown(...)to the .post(Runnable) and .runOnUiThread(Runnable)
All the methods of PopupWindow which should show it.
PopupWindowCompat.showAsDropdown(...) method.
All this things didn't help me.
Meanwhile a PopupMenu class correctly displays in the same context. But I need PopupWindow.
What should I do to show PopupWindow?
Follow this method, May help you.
private void showPopupWindow(View view){
LayoutInflater mLayoutInflater=LayoutInflater.from(this);
View mView=mLayoutInflater.inflate(R.layout.pop_up_layout, null);
mPopupWindow = new PopupWindow(mView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
// mPopupWindow=new PopupWindow(mView,,LayoutParams.WRAP_CONTENT);
mPopupWindow.setContentView(mView);
Button mBtnCancel=(Button) mView.findViewById(R.id.btn_cancel);
mBtnCancel.setOnClickListener(this);
mPopupWindow.showAsDropDown(view, 0, 0, Gravity.LEFT);
mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
#Override
public void onDismiss() {
Drawable d = new ColorDrawable(Color.WHITE);
getWindow().setBackgroundDrawable(d);
}
});
}

Pop up window to display some stuff in a fragment

I am trying to make something like a pop-up window, that would appear when clicked on a view in a fragment. I want this pop-up window or whatever, to not make the fragment dark, like a Dialog Fragment does.
And I also want the pop up to be positioned where the view is clicked.
Would be good if it has its own activity and layout so I can do some custom changes in it.
Can you plese show me some sample code?
The following should work perfect in accordance with your specification. Call this method from inside onClick(View v) of OnClickListener assigned to the View:
public void showPopup(View anchorView) {
View popupView = getLayoutInflater().inflate(R.layout.popup_layout, null);
PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// Example: If you have a TextView inside `popup_layout.xml`
TextView tv = (TextView) popupView.findViewById(R.id.tv);
tv.setText(....);
// Initialize more widgets from `popup_layout.xml`
....
....
// If the PopupWindow should be focusable
popupWindow.setFocusable(true);
// If you need the PopupWindow to dismiss when when touched outside
popupWindow.setBackgroundDrawable(new ColorDrawable());
int location[] = new int[2];
// Get the View's(the one that was clicked in the Fragment) location
anchorView.getLocationOnScreen(location);
// Using location, the PopupWindow will be displayed right under anchorView
popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY,
location[0], location[1] + anchorView.getHeight());
}
The comments should explain this well enough. anchorView is the v from onClick(View v).

Categories

Resources