Add View into RecyclerView - android

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.

Related

when i set popup outside touchable to false edit text does not showing keyboard in pop up window

I have a PopupWindow on my activity, the popupWindow has Edit text. The thing is when i set popup Window outside touchable to false Edit text does not opening keyboard in pop up window in android and i am dismissing the popup by giving cancel button inside popup. Please help thanks in advance.
LayoutInflater inflater = (LayoutInflater)
getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = inflater.inflate(R.layout.repeat, null);
int width = LinearLayout.LayoutParams.MATCH_PARENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = false;
final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);
// show the popup window
// which view you pass in doesn't matter, it is only used for the window tolken
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
final LinearLayout until = popupView.findViewById(R.id.Until);
Button pop_done = popupView.findViewById(R.id.pop_done);
Button pop_cancel = popupView.findViewById(R.id.pop_cancel);
dropdown = popupView.findViewById(R.id.spinner);
final EditText repetition = popupView.findViewById(R.id.repeat_times);
Try this
LayoutInflater inflater = (LayoutInflater)
getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = inflater.inflate(R.layout.repeat, null);
int width = LinearLayout.LayoutParams.MATCH_PARENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
final PopupWindow popupWindow = new PopupWindow(popupView, width, height);
popupWindow.setFocusable(true);
popupWindow.update();
// show the popup window
// which view you pass in doesn't matter, it is only used for the window tolken
popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);
popupWindow.setOutsideTouchable(false);
final LinearLayout until = popupView.findViewById(R.id.Until);
Button pop_done = popupView.findViewById(R.id.pop_done);
Button pop_cancel = popupView.findViewById(R.id.pop_cancel);
Spinner dropdown = popupView.findViewById(R.id.spinner);
final EditText repetition = popupView.findViewById(R.id.repeat_times);

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.

How to adjust popup menu when pop outside container

I am using a custom popup menu that pops inside a RecycleView container.
When the view touched is the on at the bottom, the popup menu hides the controls bellow the RecycleView.
I want to adjust the popup position in this case, bringing the popup up the exact distance needed so the menu keeps inside the container.
This should be easy, but i am having difficulties getting the coordinates and applying the calculations from inside the Adapter that deals with clicks on items.
Here is what i managed so far:
void show(FragmentActivity activity, View touchedView, DataItem item) {
LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.popup_menu, null);
PopupWindow popupWindow = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
bind(popupWindow, popupView, item);
//draws the menu perfectly bellow the touched element,but doesn't take in account the parent view area
popupWindow.showAsDropDown(touchView);
}
This is what I did:
private void showPopupMenu(final View view, final int position) {
// inflate menu
final PopupMenu popup = new PopupMenu(view.getContext(), view);
popup.setGravity(Gravity.END);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.popup_menu, popup.getMenu());
popup.show();
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
final EditText editText = (EditText) promptView.findViewById(R.id.input_text);
// setup a dialog window
alertDialogBuilder.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
And here is the outcome:
Found out. 2 Things were on the way and are explained in comments.
void show(FragmentActivity activity, View touchView, IDataItem dataItem) {
LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.popup_menu, null);
PopupWindow popupWindow = new PopupWindow(
popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
bind(popupWindow, popupView, dataItem);
//1º problem: View item is inside ViewHolder.Item, so container is 2 levels up and touched item one level up.
View container = (View) touchView.getParent().getParent();
View item = (View) touchView.getParent();
int containerHeight = container.getHeight();
//2º problem: to get size before the popup view is displayed: ref:https://stackoverflow.com/a/15862282/2700303
popupView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
int yOff=0;
//if popup view will draw pass the bottom, get the amount needed to adjust the y coordinate
if (ContainerHeight < item.getHeight() + item.getTop() + popupView.getMeasuredHeight())
yOff = ContainerHeight- (item.getTop() + item.getHeight() + popupView.getMeasuredHeight());
popupWindow.showAsDropDown(touchView,0,yOff);
}

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.

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