Hi,
I've identified a problem with a SeekBar being inside a ListView, and
a problem with a SeekBar being inside a Preference on Android 2.2. I'm
trying to figure out if I'm doing something wrong, or this is a
limitation/bug of Android.
The first problem with the ListView is that I am unable to use the
trackball/arrow keys to move the SeekBar when it is inside a ListView.
This seems to apply to all versions of Android 1.5-2.2. The following
simple example shows this:
public final class TestActivity extends ListActivity {
public SeekBar makeSeekBar() {
SeekBar s = new SeekBar(this);
s.setMax(10);
s.setKeyProgressIncrement(1);
return s;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new BaseAdapter() {
@Override
public int getCount() {
return 5;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
return makeSeekBar();
}
});
}
}
The previous example code creates a ListActivity with a simple
ListAdapter which displays 5 SeekBars. Each SeekBar seems to work
correctly when in touch mode, but I am unable to move the bar left of
right by using the arrow keys (in the emulator) or the trackball (on
my G1). If I instead make a Activity with a SeekBar in it, then the
arrow keys/track ball can easily move the SeekBar left and right. Is
this a limitation? or just an oversight? or am I missing something?
The second problem (with led me to the first problem), is I have a
custom Preference class called SeekBarPreference, which if you can't
guess displays a SeekBar on a PreferenceActivity. It doesn't display
the SeekBar in a popup dialog, but instead directly in the
PreferenceActivity[1]. This works great in touch mode, unless I use
Android 2.2. On Android 2.2 it seems every time I start to slide the
bar left or right, as soon as it moves one notch a onStopTrackingTouch
is received, and the bar no longer slides. So basically the SeekBar
will only move to where you click and no longer slides. Under Android
1.6-2.1 the slide behaviour worked fine!.
I did some debugging, and the call stack from the onStopTrackingTouch
is as follows:
SeekBarPreference.onStopTrackingTouch(SeekBar) line: 110
SeekBar.onStopTrackingTouch() line: 115
SeekBar(AbsSeekBar).onTouchEvent(MotionEvent) line: 311
SeekBar(View).dispatchTouchEvent(MotionEvent) line: 3766
RelativeLayout(ViewGroup).dispatchTouchEvent(MotionEvent) line: 936
LinearLayout(ViewGroup).dispatchTouchEvent(MotionEvent) line: 936
LinearLayout(ViewGroup).dispatchDetachedFromWindow() line: 1148
ListView(ViewGroup).removeDetachedView(View, boolean) line: 2333
AbsListView.access$2700(AbsListView, View, boolean) line: 72
AbsListView$RecycleBin.addScrapView(View) line: 4068
ListView.layoutChildren() line: 1514
ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1147
ListView(View).layout(int, int, int, int) line: 7035
FrameLayout.onLayout(boolean, int, int, int, int) line: 333
FrameLayout(View).layout(int, int, int, int) line: 7035
PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int,
int) line: 333
PhoneWindow$DecorView(View).layout(int, int, int, int) line: 7035
ViewRoot.performTraversals() line: 1045
ViewRoot.handleMessage(Message) line: 1727
ViewRoot(Handler).dispatchMessage(Message) line: 99
>From this I can see that the ListView is removing the view with the
SeekBar in it (inside removeDetachedView) which calls
dispatchDetachedFromWindow and fires a MotionEvent.ACTION_CANCEL
event, causing the Tracking to stop.
I have not been able to figure out why the ListView is detaching the
SeekBar's view, and this does not seem to happen in my simple ListView
case. I will continue to debug the problem and generate a simple test
case others can use, but I thought I better ask.
thanks for any help on either problems
Andrew
[1] Shameless plug, but if anyone wants to see the SeekBarPreference
in action, download my new app "MusicGrid" and view the settings. As I
say the problem only appears on 2.2 phones.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en