I have a tablet app with a Master / Detail layout, with a TableView in the Master panel that changes the content of the Detail pane. I'd like to have the master's row stay highlighted when clicked like it does in the android OS settings.
Right now the best I'm able to do is set the backgroundColor to a new color in response to a 'click' event. However, when I do a quick tap, the row highlights, then blinks back to normal before highlighting again. I'm guessing this is the delay between when I lift my finger off and when the backgroundColor gets changed.
tableview.addEventListener('click', function(e) {
...
else if (e.rowData.id == 3) { // scan history
e.row.backgroundColor = 'blue';
This appears to be the way others have done it: http://developer.appcelerator.com/question/124359/android---tableviews-deselectrow
And if I was just using android and not Titanium: How can I highlight the table row on click ?
Try this instead. The touch start is called immediately, while the click usually is not. Note that according to the docs a scroll event and a touch event cant happen concurrently for iOS and Android, so you probably want to handle the touchcancel event also if you have a `touchstart`` listener.
tableview.addEventListener('touchstart', function(e) {
...
// Get the source row, and then get its id
else if (e.source.id == 3) { // scan history
e.row.backgroundColor = 'blue';
});
EDIT:
Maybe a better way to do this would be to handle the touchend event. This would handle bothe the quick taps, the user sliding to a different row, and the scrolling edge cases.
When creating your row, use:
selectionStyle : "NONE"
This prevents it from changing color on click/touch
And roll your own event listeners to govern exactly when your row is highlighted.
The iOS blue row selection color is something like: "#006EF1"
Related
I am trying to implement the listview with swipe to delete and undo in my project. it works fine.code for demo is Here.
But my need is to handle click event for each view, each view have some action to perform.
According to this image, view which one is in middle(data 1, data 2) have a clickListener, when i swipe from right to left by put the finger on lastview(yellow or grey round) it detect the swipe but when i try to swipe from middle Textview (data 1, data 2) it not allow me to swipe from textview(data 1 , data 2).
my need is to start swipe from any where in list row and also handle click of each view (inside row like edittext, Textview and Imageview).
Can anybody help me to come out from this?
all you need is a some research about ViewGroup.onInterceptTouchEvent() method
Is it possible to simulate the event of anchors (html) with the Android interface?
I mean I have a listview with several titles and I want to press a button that moves the screen to the specific title.
If you know the position of the item in the List, you can use setSelection() in your button's click handler.
http://developer.android.com/reference/android/widget/ListView.html#setSelection%28int%29
So I have an interesting problem. I have a ListView that I want to maintain the exact row selection and yoffset on an orientation change. As such I call:
list.postDelayed(new Runnable() {
#Override
public void run() {
list.requestFocusFromTouch();
list.setSelectionFromTop(finalPosition, yoffset);
}
},100);
Seems pretty straightforward and it works well. The problem is that when I change the orientation twice (get back to the original orientation, ie landscape->portrait->landscape) than the list has exited TouchMode, ie list.isInTouchMode() returns false (On the first orientation change, list.isInTouchMode() returns true and everything is great, clicking works etc). As such when you scroll the listview programatically using setSelectionFromTop() and click on an item in the list without touching somewhere else in the app first, the list jumps and scrolls to where I clicked, highlighting the wrong item. It's very annoying and I can't seem to find a fix for it. Any ideas and suggestions are most welcome.
Calling list.requestFocusFromTouch() seems to have no effect on setting TouchMode.
More info:
Android:To set an item as selected when the ListView opens?
I found a post from Romain Guy "Whenever you touch the screen, anywhere in the phone, you enter touch
mode for all of the applications. This is the desired and expected
behavior. " http://groups.google.com/group/android-developers/browse_thread/thread/590b02939d14675b/077ad77e4217e56e?lnk=gst&q=[android]+scroll+listview+not+in+touchmode#077ad77e4217e56e
All i want to do is somehow get into TouchMode without forcing the user to actually touch the device on the second orientation change. I have tried list.dispatchTouchEvent() multiple times. Its possible I am sending the wrong motion events:
list.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN ,
list.getWidth(), list.getHeight(), 0));
list.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE ,
list.getWidth(), list.getHeight(), 0));
list.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(), MotionEvent.ACTION_UP ,
list.getWidth(), list.getHeight(), 0));
Another option would be to figure out why we are no longer in TouchMode. I have not overriden onConfigurationChanged() so the layout is completely rebuilt on each orientation change.
Thanks in advance!
Jared
Try using setItemChecked(...) method of the Listview. I've seen that used a fair bit when the Listview is set to CHOICE_MODE_SINGLE, as that mode really makes each listview item a checkable object.
Also look at the following QA where someone was trying to do something similar. It appears that the easiest solution was to create a different background for 'checked' items.
Android listview array adapter selected
i have a simple list view control
my queries are:
1) how to set first row selected on start (after fill data in list view)
2) when i navigate by hardware button i got AdapterView.OnItemSelectedListener and color of row background change, but when i click i not get any OnItemSelectedListener and no row selected. How to select row on click.
3) when i change focus list row selection removed,
please any one with any solution, code example or articles
i search but no susses
with regards
Chandra Kant Singh
how to set first row selected on start
(after fill data in list view)
Call setSelection() on the ListView. However, this only will have a visual effect if the user entered your activity via the pointing device (trackball, D-pad, etc.).
How to select row on click.
You don't.
when i change focus list row selection
removed,
If I understand what you mean by "change focus", this is working as designed.
Please review this article on touch mode and the use of the "selected" state, then adjust your UI design to follow Android conventions. Selection is only used when the user navigates with the pointing device, not when the user uses the touch screen.
I am displaying a radio schedule in a List View and would like to highlight the currently playing program. I also want to allow the user to click on any program and get more details for the program. I have tried the following:
radioView.setSelection(adapter.getCurrentProgramIndex());
radioView.setSelected(true);
This does scroll the list down to the selection which is good, but it does not highlight the selection. I understand this is because the device is not in touch mode, but how then would I go about highlighting the current program?
how then would I go about highlighting
the current program?
Change something in that list row. For example, perhaps you have an icon you can switch to be a "playing" icon, or have an icon that is formerly INVISIBLE become VISIBLE, or something.
Bear in mind that you will need to have these smarts in your row binding code, so that if the user scrolls, you correct undo and redo that setting -- otherwise, row recycling will make it appear that other programs are playing.