I got a RelativeLayout and I'm trying to remove a view from it. I tried removeViewAt and removeView but the view is still there even after I call them. Do you guys know what could be wrong?
RelativeLayout v = (RelativeLayout)findViewById(R.id.container);
Button btn = new Button(this);
v.addView(btn);
v.removeView(btn);
Related
Im having a bug that i cant understand the reason and how to resolve it. I belive that is a problem of layout/view/context refresh but i dont know.
I have a cell from a listView(I prefer recyclerView but the project has years) and in the corner of the cell i have a button to show more options. Programatically it just make an element View.GONE and another element View.VISIBLE.
I will attach code in a moment
To this button i setted too a listener that when i tap on it it do the opposite of below mentioned. It shows some elements and hide an entire LinearLayout from the cell. The elements are showed BUT the LinearLayout keeps on the screen like bugged. If i tap anywhere it disappears and if i try to tap on it it disappears too. Its like the view of that linear got bugged and keep in there like a ghost view. I will shop some pictures.
The cell normally at the beginning: https://imgur.com/1BjK0KP
The cell after i press the entire view to show the LinearLayout at the bottom of the cell: https://imgur.com/eONSptW
The cell after i press the arrow of the corner to hide the LinearLayout. Here it shows the view bugged https://imgur.com/jrT0qxV
The cell after i tap anywhere else https://imgur.com/XD1jN7U
public void expandView(View view){
final View cellView = view;
final LinearLayout editLinear = (LinearLayout) view.findViewById(R.id.cart_edit);
editLinear.setVisibility(View.VISIBLE);
final TextViewFont countText = (TextViewFont) view.findViewById(R.id.itemCount);
countText.setVisibility(View.GONE);
final TextViewFont total = (TextViewFont) view.findViewById(R.id.itemTotal);
final ImageView imageViewArrow = (ImageView) view.findViewById(R.id.cart_edit_image);
imageViewArrow.setImageDrawable(context.getResources().getDrawable(R.drawable.icon_arrow_up));
//notifyDataSetChanged();
imageViewArrow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
countText.setVisibility(View.VISIBLE);
editLinear.setVisibility(View.GONE);
imageViewArrow.setImageDrawable(context.getResources().getDrawable(R.drawable.icon_arrow_down));
}
});
First of all, you don't need to store context because in View you have the method view.getContext().
I recommend this article:
https://possiblemobile.com/2013/06/context/
On the other hand, ensure that you don't have a ghost view that is overlapping your image view.
I have one filter button.I need to open expandable/dropdown filter same as given below image.I tried popup menu and Listpopup window but,I did not get any success.
Thanks in advance
you can make use of fragment which will be below the filter button,layout will include the ui you expect i.e upper arrow and expandable view or any view you are using..
After clicking on filter just visible the fragment and with fragment transition,for the effect you can use animation too...
This i already done,you can refer carwale app used car section..click on filter button one same dilog will come..
for any thing let me know further..
I did code by the help of above comments. but the code looks as below.
final View popUpView = getLayoutInflater().inflate(R.layout.exp, null);
listPopupWindow = new PopupWindow(popUpView, LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT, true);
expandableListView= (ExpandableListView) popUpView.findViewById(R.id.expandableListView);
btnticker.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
expandableListDetail = ExpandableListDataPump.getData();
expandableListTitle = new ArrayList<String>(expandableListDetail.keySet());
expandableListAdapter = new CustomExpandableListAdapter(MainActivity.this, expandableListTitle, expandableListDetail);
expandableListView.setAdapter(expandableListAdapter);
listPopupWindow.showAsDropDown(v);
}
});
I want to add an ImageView within the onClick() of the Button. But the ImageView should be aligned to the centre of the button.
How can I do this pragmatically?
I'm creating a new instance of the ImageView to be added on top of the View that called it and it's position is equivalent of the View that called it.
How can I get the X and Y coordinates?
EDIT:
#Override
public void onClick(final View v) {
if(v.getWidth() > v.getHeight()) size = v.getHeight();
if(v.getWidth() < v.getHeight()) size = v.getWidth();
RelativeLayout.LayoutParams button = new RelativeLayout.LayoutParams(size,size);
buttonc = new ImageView(getApplicationContext());
buttonc.setBackgroundResource(R.drawable.round);
layout.addView(buttonc,button);
I'm using the above code to attempt to pragmatically set the size of the ImageView to that of the button, and it's working.
As for the coordinates, I still haven't figured it out.
To add clarity: I'm attempting to create a rounded ripple effect over the view that calls it.
I suggest a better solution create an image view before hand place it in the xml as you see fit,at first set its visibility to false .
On click switch its visibilty to true, and the image will appear
This solution is easier than what you are searching.
Feel free to ask questions
to add Imageview
#Override
public void onClick(final View v) {
//LinearLayout
LinearLayout linearLayout= new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
//ImageView
ImageView imageView = new ImageView(this);
//image resource
imageView.setImageResource(R.drawable.specs);
//image position
imageView.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
//adding view to layout
linearLayout.addView(imageView);
//make visible to program
setContentView(linearLayout);
}
I have set a linear layout inside a alert dialog in which I basically have a few Edit texts.
The problem I am facing is that I am not able to scroll down to see every edit text created dynamically.
Here's the snippet:
Context context = this.getApplicationContext();
LinearLayout layoutCreateMerch = new LinearLayout(context);
layoutCreateMerch.setOrientation(LinearLayout.VERTICAL);
layoutCreateMerch.setVerticalScrollBarEnabled(true);
final AlertDialog.Builder alert = new AlertDialog.Builder(Act.this);
alert.setTitle("Submit");
final EditText Name = new EditText(Act.this);
final EditText Desc = new EditText(Act.this);
...
...
So, How can I add a scroll view at runtime in this alert dialog's Linear Layout?
I suppose LinearLayouts don't need a scroll bar/view but this isn't working out for me :|
Also, inflating this would be other option but for now..can I do something abt this?
Thanks for reading.. :)
In theory it goes like this:
ScrollView scroll = new ScrollView(context);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
scroll.addView(yourLinearLayout);
sO basically just put you linearLayout to ScrollView and set it as dialogView in the end like,
alertDialog.setView(scroll);
Please use <ScrollView ></ScrollView> to wrap your layout.
I have a Popup which holds a couple of EditTexts in a ScrollView.
When i click on an EditText it scrolls up the View in background, not the Popup, therefore the keyboard blocks the EditText.
Any ideas ?
PopupWindow popUp = new PopupWindow(this);
popUp.update(0, 0, display.getWidth(), display.getHeight());
popUp.setFocusable(true);
LinearLayout llh = new LinearLayout(this)
llh.setOrientation(LinearLayout.HORIZONTAL);
ScrollView sv = new ScrollView(this);
EditText e1,e2,e3...
llh.addView(e1);
llh.addView(e2);
llh.addView(e3);
...
sv.addView(llh);
popUp.setContentView(llh);
popUp.showAtLocation(llh, Gravity.BOTTOM, 0, 0);
This is "launched" from a View which holds a ScrollView aswell.
If there is a workaround for this, it would be great.
I have faced the same problem as you, and to solve it, i created a custom Dialog and with a custom theme (R.style.ThemeDialogCustom in the following example). I also set dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) and dialog.setCanceledOnTouchOutside(true); and i set a custom layout with setContentView. Something like this:
Dialog dialog = new Dialog(activityContext, R.style.ThemeDialogCustom);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(R.layout.custom_dialog_layout);
In other words, the above piece of code tries to immitate the behavior of a PopupWindow.
EDIT For clarification purposes, if you need to access a view that was defined in the dialog's custom layout, you can access it like this:
EditText e1 = (EditText) dialog.findViewById(R.id.e1);
Hope that helps.