I have an app that uses an ExpandableListView widget filled with items via a BaseExpandableListAdapter. The app was built for the Android Version 1.6, and when I test it using the Android Emulator (version 1.6 build) everything works fine. I can scroll the list up and down and when I tap on any items in the list I get a onChildClick() event.
However, when I try to run this same app on an real Android phone (running Gingerbread), I only get onChildClick() events if I don't scroll the ExpandableListView. If I scroll the list too much, I no longer get onChildClick events (nor itemClickEvents also).
So I'm baffled. Why do I not get any onChild or onItem click events for the listview items after I scroll it? Note, that if I scroll it just a small amount (say, 2 or three lines) I do get click events, but any more scrolling and then I no longer get click events for any item in the list.
Any suggestions or advice would be appreciated.
Thanks.
Ok, I'm answering my own question here for others who may have the same problem. The issue I'm experiencing seems to be related to the focus status of the ExpandableListView Widget. When I scroll the list, the ListView widget seems to lose focus and I can't select any of the listed items. I'm not sure what the best way is to correct this, but I did get this to work.
I added a scroll listener for the ListView widget as show:
getExpandableListView().setOnScrollListener(this);
I then added a method to my activity that would set the focus back to the ListView Widget once it is finished scrolling:
#Override
public void onScrollStateChanged(AbsListView view, int scrollState)
{
// - this method is called when there is a scroll event in the main ExpandableListView widget.
// - after the user stops scrolling the listview, make sure to set the focus to the widget
if ( scrollState == OnScrollListener.SCROLL_STATE_IDLE )
{
ExpandableListView elv = getExpandableListView();
elv.requestFocusFromTouch();
}
}
Now that seems to fix my issue. I'm sure there's a better way (and if you know of one, please post it here), otherwise my "hack" seems to work ok.
Hope it helps someone with a similar issue.
Thanks, this answer solved my problem on losing focus on while scrolling.
ListView mRecentSearchList;
mRecentSearchList.setOnScrollListener(new OnScrollListener(){
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//adapter.notifyDataSetChanged();
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
//adapter.notifyDataSetChanged();
if(scrollState == OnScrollListener.SCROLL_STATE_IDLE ||scrollState == SCROLL_STATE_TOUCH_SCROLL || scrollState == SCROLL_STATE_FLING)
{
mRecentSearchList.requestFocusFromTouch();
}
}
});
I have experienced exactly the same problem and I found that it was caused not by list itself but adapter(ResourceCursorTreeAdapter). To prevent groups to collapse I was doing a hack as follows in my adapter:
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View view = super.getGroupView(groupPosition, isExpanded, convertView, parent);
ExpandableListView list = (ExpandableListView) parent;
list.expandGroup(groupPosition);
return view;
}
If you do the same, please try replacing this with different solution.
In my case I've used the same solution proposed by cohoman, however the requestFocus() method provided me a better user experience:
navList.setOnScrollListener(new OnScrollListener()
{
#Override
public void onScrollStateChanged(AbsListView view, int scrollState)
{
if(scrollState == OnScrollListener.SCROLL_STATE_IDLE)
{
navList.requestFocus();
}
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
// TODO Auto-generated method stub
}
});
Related
I have set up setOnScrollListener event on my listview its working good in mobile here is my code
movieList.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
userScrolled = true;
}
}
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if(userScrolled && (firstVisibleItem + visibleItemCount >= totalItemCount)){
pageNum++;
int index = movieList.getFirstVisiblePosition();
float indexY = movieList.getScrollY();
load_loader.setVisibility(View.VISIBLE);
getMovies();
movieList.setSelection(index);
userScrolled = false;
}
}
});
Now i have installed my app to android tv box my full app is working good in tv box but list view not loading more records i think because of touch scroll tv is not touch its operated by remote navigation please help me to solve this problem thank you
Try setting listView.setItemsCanFocus(true); to your ListView so that focusable views inside of your listItems won't be ignored. Source.
You may also check this documentation on how you can actually navigate around your app when using remote control buttons instead of a touch screen.
I have a layout which requires me to put a grid view inside a scroll view, i have read this is not suggested but my layout requires this.
When inserting a GridView in a ScrollView the grid does not scroll! I have got around this with the following.
The problem i have is that i have is the grid view will not scroll smoothly, if i hold my finger down and drag it scrolls, but if i do a swipe type of gesture it does not do a smooth scroll as expected. as soon as i remove my finger the scrolling stops on the grid view.
gridView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN
|| event.getAction() == MotionEvent.ACTION_MOVE) {
gridView.requestDisallowInterceptTouchEvent(true);
}
return false;
}
});
i tried adding this but no luck
gridView.setOnScrollListener(new OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView view,
int scrollState) { // TODO Auto-generated method
// stub
}
#Override
public void onScroll(AbsListView view,
int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
// TODO Auto-generated method stub
gridView.requestDisallowInterceptTouchEvent(true);
}
});
EDIT:
Just to give a bit more information
the grid view is inserted programatically, inside a relative layout which sits in a linear layout inside a scrollview
I would Suggest you to use ExpandableHeightGridView. It works for me very fine.Hope this will help you :)
To Answer my own question, i found a solution taking some parts from this example, works perfectly
https://github.com/Durgadass/ScrollInsideScroll
I have problem with context menu when using android-swipelistview-sample from 47deg .(https://github.com/47deg/android-swipelistview). Problem is that when short click is made context menu is displayed .
How to show context menu just for long click ?
This bug is caused by curved touch event distribution in 47degrees swipe listview.
To fix this, just comment out
view.onTouchEvent(motionEvent);
in onTouch() method, in the end of switch case MotionEvent.ACTION_DOWN: in SwipeListViewTouchListener. Issue will go away, but scrolling your ListView will become dull, as soon, as your touch events will not be recognized while the listview is scrolling.
To overcome this problem, simply add to your SwipeListView class new flag, something like isScrolled.
Then, you need to update this flag each time, the scrolling state changes:
mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
#Override
public void onScrollStateChanged(AbsListView absListView, int i) {
mListView.setScrolling(i == SCROLL_STATE_FLING);
}
#Override
public void onScroll(AbsListView absListView, int i, int i2, int i3) {
}
});
And finally, make it distribute touch event only when the view is scrolling:
if(swipeListView.isScrolling()){
view.onTouchEvent(motionEvent);
}
Good luck!
I think you were implementing the code on onItemLongClick, try creating context menu public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo)
where you will setup the menus.
Hope this helps you.
I use Listview with Remote Control (Q1 Himedia SettopBOx)
Now down and up keydown ،How do I know where I am in listview
for example: when arrived in last item in listview then list refreshed or going to first item?
Please Help Me....
thanks
Take a look at OnScrollListener of ListView. You can set a new callback using ListView.setOnScrollListener() and get first visible item position and number of visible entries by implementing onScroll function of the listener.
Use an OnScrollListener for the listview like so.
myListView.setOnScrollListener(new OnScrollListener()
{
#Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount)
{
// Your code goes here. Determine the position with the firstVisibleItem.
}
#Override
public void onScrollStateChanged(AbsListView view, int scrollState)
{
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING)
{
Log.d(TAG, "User is flinging through the view");
}
}
});
We have used Custom List View inside that one Text View and two Edit text present. I have put On Item CLick Listener On the Edit text Listener is set properly. What Is problem when fling action is happen then that listener is not setting. Is their any other Listener which can help me to control fling action.
may be you can't control the flying action, you can listen the flying action:
ListView.OnScrollListener can listen the scroll action:
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
#Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(scrollState == OnScrollListener.SCROLL_STATE_FLING){ //flying
}
}
you can try this, hope it can help you -):