How to get view of hidden menu? - android

I must implement pop up tooltips in my android app, so I need to get View objects of interesting for me screen elements.
But I have some problem with View from toolbar menu. I need to get an object View menu item, which is shown below.
Someone knows how to get the object View of this UI element? Thanks.

I found the next is not very good, but working way to implement it.
int count = mToolbar.getChildCount();
for (int i = 0; i < count; i++) {
View view = mToolbar.getChildAt(i);
Log.e("View type ", mToolbar.getChildAt(i).getClass().getSimpleName());
if (view instanceof ActionMenuView) {
int childCount = ((ActionMenuView) view).getChildCount();
for (int y = 0; y < childCount; y++) {
View overFlowMenuButton = ((ViewGroup) view).getChildAt(y);
Log.e("ActionMenuView type", ((ViewGroup) view).getChildAt(y).getClass().getSimpleName());
if (overFlowMenuButton.getClass().getSimpleName().equalsIgnoreCase("OverflowMenuButton")) {
Log.e("Need view ", overFlowMenuButton.getClass().getSimpleName());
}
}
}
}

Related

Send a view to back in Relative Layout

I am having so many views to in a relative layout which is able to zoom and rotate. what I am trying to achieve is, when I long click a view it should able to send that particular view to last .
what I do is
private void moveToBack(View currentView) {
ViewGroup vg = ((ViewGroup) currentView.getParent());
for (int i = 0; i < vg.getChildCount(); i++) {
View v = vg.getChildAt(i);
if (!v.equals(currentView)) {
vg.bringChildToFront(v);
break;
}
}
}
This will set the another view above the selected view I need to send that particular view to last. MIn sdk is 17 and I can't change that.
We don't have something like bringToback() method so only we could modify the order of childviews. I tried once to achieve it using tricky way :
public void sendViewToBack(View child) {
final ViewGroup mParent = (ViewGroup)child.getParent();
if (null != mParent) {
mParent.removeView(child);
mParent.addView(child, 0);
}
}

Android - Set onEditListener for all EditTexts under a parent

Is there any easy way to set onEditListener to all EditTexts under a parent instead of making them one by one?
My idea is to show a save button only when the users change their profile info on EditTexts.
Hmmm, you can call this recursion in onCreateView() if parent is fragment or onCreate() if parent is activity:
private static void enumLayout(LinearLayout ll) {
int childcount = ll.getChildCount();
for (int i = 0; i < childcount; i++){
View v = ll.getChildAt(i);
if (v instanceof LinearLayout) {
enumLayout((LinearLayout) v);
} else if (v instance of EditText) {
// set listener here
}
}
}
ll is root layout in your fragment/activity.

How to know linearlayout has reached its last child item

Actually In my project I am dynamically adding a child item inside linearLayout but when last child is reached inside linearLayout i have to load other child same as facebook scrolling. But to know when the last element of linearLayout is arrived?
getChildCount() and also getChildAt() like this may be help you -
int childcount = ll.getChildCount();
for (int i=0; i < childcount; i++){
View v = ll.getChildAt(i);
if(i == (childCount -1)){
// Do your Task here
}
}
Code snip :
LinearLayout myLayout;// ur layout
int childCount = myLayout.getChildCount();
View v = null;
for(int i=0; i<childCount; i++) {
v = layout.getChildAt(i);
//do something with your child element
}

Restrict the scroll up of list view after a particular row

The title is little confusing let me explain my problem ,i have some data in list view and its is scrollable and there is no issue in that sort of problem.my requirement is while i scroll and for example the list views first visible portion is 2 then it should stop the scroll up.But we can scroll down,its like restring the scroll up of list view after a particular row is the first visible item in that list view.i tried some of the code but it has a problem it disable the entire scroll i cant scroll down the list view i use this method to disable the scroll of listview
public void enableDisableView(View view, boolean enabled) {
view.setEnabled(enabled);
if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
for (int idx = 0; idx < group.getChildCount(); idx++) {
enableDisableView(group.getChildAt(idx), true);
}
for (int idx = 0; idx < group.getChildCount(); idx++) {
enableDisableView(group.getChildAt(idx), true);
}
}
}
i also used
mListView.setSelectionFromTop(1, 0);,smooth scroll etc
but it does not works.is there any idea or solution to achieve this aim.
Thank you

Disable all items inside linear layout including items inside nested linear layouts

I want to disable all the field inside the scroll view shown in the picture. I tried using the code below but the code only disables the direct child of linear layout and doesn't disable child for the nested linear layout. How can I disable all child including the children of nested layouts?
LinearLayout myLayout
= (LinearLayout)v.findViewById(R.id.addEditSection1);
for (int i = 0; i < myLayout.getChildCount(); i++) {
View view = myLayout.getChildAt(i);
view.setEnabled(false);
}
Try this recursive function:
public void disableAllViews(View v){
v.setEnabled(false);
if(v instanceof ViewGroup){
for (int i = 0; i < ((ViewGroup)v).getChildCount(); i++) {
View view = ((ViewGroup)v).getChildAt(i);
disableAllViews(view);
}
}
}
And call it as
LinearLayout myLayout
= (LinearLayout)v.findViewById(R.id.addEditSection1);
disableAllViews(myLayout);
Quiet trivial: You got to check recursive.
E.g.:
protected void disableViewElements(ViewGroup container) {
for (int i = 0; i < container.getChildCount(); i++) {
if(container.getChildAt(i) instanceof ViewGroup ) {
disableViewElements((ViewGroup) container.getChildAt(i));
}
else {
View view = container.getChildAt(i);
view.setEnabled(false);
}
}
}
This is really easy with droidQuery:
$.with(myLayout).selectAll().disable();
I am using this in my project
public void setAllViewsEnabled(View view, boolean enabled) {
if (view instanceof ViewGroup)
for (int i = 0; i < ((ViewGroup)view).getChildCount(); i++)
setAllViewsEnabled(((ViewGroup)view).getChildAt(i), enabled);
view.setEnabled(enabled);
}
You can check to execute the last line weather the current view is a TextBox. You can also decide to enable it after using this function.
Remember that if you disable a nested ViewGroup vg1 and then you disable the containing ViewGroup vg0, re-enabling vg0 will result in enabing also vg1. To prevent this you have to save a boolean for each ViewGroup and to change the method.

Categories

Resources