Android ExpandableList Disable Groups - android

I have an expandable list with all groups always expanded and the groups not collapsable. The problem is that even if I made the groups to not collapse when I click on them the "select" effect is still visible and I don't want it to be visible. How can I do that?
Any answer would be appreciated.
Thanks

I have figure out myself after all how to do that :D I have put this code:
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent event) {
return true;
}
});
in the adapter of the ExpandableList in the getGroupView method. And now it's working.

Normally when you click on the group name, it collapses automatically. Here is an example of expandableListView. Moreover, I could hardly make any comment unless I see what you did.

Related

Android EditText field like button

I am trying to cope with one (seemed to be) smalll thing. In my app I've got one activity with two EditText fields.
I want one of them to be normall field (etNormal), and the other (etButton) behave more like button, so when you touch it, the keybord is not shown but instead the sliding drawer is opened. If sliding drawer is opened and you will press the normall edittext sliding drawer will hide.
I've tried adding OnClickListener and OnTouchListener (not in same tries) to both with condition if etButton was clicked/touched open sliding drawer, if not then close.
The outcome was strange. When it was OnTouchListener test it was more like toggle, so when I pressed one drawer opens and on another close. When it came to OnClickListener I needed to press each edtitext twice to get action done.
And to hide keybord in etButton I am using setInputType(InputType.TYPE_NULL);. I've tried also setEnabled(false); but then I was even unable to click/touch it. The one defect of currently used method is when I am changing click from etNormal to etButton, the keyboard is still shown and it doesn't hide.
So, can anyone tell me what I can do to achive my goal?
EDIT:
I've erad your current suggestions and modified a little my code, but still it is not working.
This is a part of it where I am assigning OnTouchListener:
OnTouchListener touchListener = new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent ev) {
if(v==etButton && ev.getAction()==MotionEvent.ACTION_DOWN) {
slidingDrawer.animateOpen();
}else {
slidingDrawer.animateClose();
}
return false;
}
};
etNormal1.setOnTouchListener(touchListener);
etNormal2.setOnTouchListener(touchListener);
etButton.setOnTouchListener(touchListener);
Also in etButton declaration in XML layout file I have:
android:focusable="false"
But now, on etButton touch nothing hapens (only sliding drawer hides if was opened), and when etNormal1 or 2 is touched sliding drawer shows up or hides depending what was first (in other words toggel).
Any idea, what is wrong here?
Got an editText working like that with
android:focusable="false"
android:clickable="true"
Then an OnClickListener to override the action
In addition to above answers, I hide cursor using cursorVisibility!
android:focusable="false"
android:clickable="true"
android:cursorVisible="false"
android:focusableInTouchMode="false"
cursorVisible To show/hide the cursor on clicking the EditText
focusable To gain focus when user is touching the view, like EditText
focusableInTouchMode To keep a view selected. (select and click are different)
For detailed understanding, refer here
In your layout, add the following attribute to the EditText
android:focusable="false"
android:focusableInTouchMode="false"
Next, write method to handle the click on the EditText and add your application logic .
If you are using onTouch event, when you click the edittext, you will get two events with action as MotionEvent.Action_down and action Up. so basically it will give the effect of clicking the edit text twice. can you please provide the code so that we can have a deep look.
ReWrite your code as :
OnTouchListener touchListener = new OnTouchListener() {
boolean isOpen=false;
#Override
public boolean onTouch(View v, MotionEvent ev) {
if(v==etButton && ev.getAction()==MotionEvent.ACTION_UP) {
if(!isOpen){
slidingDrawer.animateOpen();
}else{
slidingDrawer.animateClose();
}
isOpen=!isOpen;
}
return false;
}
};
If etButton needs to be an EditText (why not a button, if it should behave like one?), maybe you could set an onFocusChangeListener. Once it gets the focus, you can show the drawer...?
Not sure about not showing the keyboard...
EditTexts are tricky. The reason why you have to press twice when you have use an OnClickListener is that the first time around the EditText gets focus and this consumes the touch event, in that case the OnFocusListener is triggered. When you touch the second time, the EditText already has Focus so now a click event is triggered.
I would suggest you try to do this without EditTexts. That would in any case yield a cleaner and simpler solution. Why exactly do you want to use EditTexts instead of Buttons?

Alternative to ListView inside a ScrollView

I have been trying to hack a ListView into a ScrollView. As many threads have pointed out, this is a very bad practice (see How can I put a ListView into a ScrollView without it collapsing?). I am currently measuring the height of my ListView and fixing its size using the solution proposed here (https://stackoverflow.com/a/3495908/924217), which works perfectly for equal height rows, but is measured incorrectly for variable height (reports min height for all rows). For quick and dirty fix, does anyone know how to measure the height properly for variable height rows?
More appropriately, can anyone point me to a good workaround using LinearLayouts. I am trying to use a ListView because I have items which I need to dynamically add and remove to the list. I cannot think of any convenient ways of doing this without adapters and the other niceties appropriated by a ListView. Can someone help me find an example of this being handled properly? Also, are there any open source projects which cover this? I have seen many people asking similar questions with little non-hacky resolve.
I would recomend that you should use listfragment so that you can dynamically add/remove items.
here parentScroll = your main scrollview and childScroll = your listview
parentScroll.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.v("PARENT", "PARENT TOUCH");
findViewById(R.id.child_scroll).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScroll.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.v("CHILD", "CHILD TOUCH");
// Disallow the touch request for parent scroll on touch of
// child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

can ListView be inside ExpandableListView?

can we have ListView inside ExpandableListView so that I can have group level first and then array of child (listView). i already finish from listview classes and it works perfectly!
but how to call each group in expandable list view to display list view (layout)! and get the correct child !
please can any one help !
thanks.
Actually you can put a scrollable view (e.g. your ListView) inside another scrollable view (e.g. your ExpandableListView) and make the former scrollable in the following way:
listView.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// disallow the onTouch for your scrollable parent view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
Yes you can! But the real thing is to create a listView in a expandableView.
Here is the trick: https://www.captechconsulting.com/blogs/android-expandablelistview-magic
Please take a look at this question which was asked two days ago. The user there was trying to put a custom view, derived from ListView into ExpandableListView. My answer to that question applies to your case as well, so I'll quote it:
You can't do that because you can't put a scrollable view(ListView)
into another scrollable view(ExpandableListView). The reason is that
the parent will consume all the touch events and they will never reach
the child. ExpandableListView will scroll, but the ListView will never
know that scrolling took place.

Items in ListView not long clickable after setting click listener in getView()

I've searched around and have not come out with a solution (maybe not using the correct keywords).
So, I've a custom ListView which its item can be dragged around when the item is long clicked. Within its item, there's an ImageView and LinearLayout containing two TextViews. Actions are done when the LinearLayout or ImageView is clicked.
To do this, I've use setOnItemLongClickListener on my DragListView which extends ListView, to initiate drag action, and onInterceptTouchEvent to manage the drag action.
Then, I have built a custom adapter extending BaseAdapter and overrided its getView() to implement the child items in the row. The LinearLayout and ImageView have been setOnClickListener.
The problem is, the LinearLayout and ImageView are able to do their stuff, but the onItemLongClick isn't called.
The listener inside getView();
holder.delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//Do something
}
For item long click (drag initiator)
setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
//Do something
}
Thank you very much!
I think that a gesture detector is one of ways to handle events.
Usually, however, a gesture detector is used when we want to detect a gesture not a long-press.
The reason why onItemLongClick isn't called is that onClickListener might consume a touch event.
In that reason, if you want to handle onItemLongClick, intercept touch event and dispatch it to views you want to handle.
You can find more details following link.
http://developer.android.com/guide/topics/ui/ui-events.html
Ok, just found out the solution myself.
Instead of using onItemLongClickListener, I create a gesture detector to detect for long press. Then I override dispatchTouchEvent and force to scan for long press first, then return super.dispatchTouchEvent and the other following touch events.
Suggestions are still welcomed!

Overriding trackpad click

I have a ListActivity; and for each item in the ListView there is a checkbox.
When you touch a list item, another Activity launches.
When you use the trackpad/trackball to highlight (read: select) an item and click the trackpad, it essentially simulates touching the item. This causes my other Activity to launch.
I would like clicking the trackpad to check the checkbox of the highlighted item. Is there a handler I can override to do this?
You need to override the onTrackballEvent(MotionEvent) method and catch ACTION_DOWN. Here is an example of how to do this:
#Override
public boolean onTrackballEvent(MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
//Do your work here
return true;
}
return super.onTrackballEvent(event);
}
Hope this works for you!
Not sure on a definite answer to this, but one thing worth researching is android:focusable.
I think your best bet is to make the List Items themselves not focusable, but the checkboxes focusable. This way when the user scrolls with the trackball/pad it will switch focus between the checkboxes instead of the list items, and behave in the way you want. This won't affect touch events.

Categories

Resources