Re: [android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-14 Thread Kostya Vasilyev

14.12.2010 20:24, bobetko пишет:

Kostya, I tried to do as you suggested. and non of it worked.
1) Don't want to add my header view into list's parent. It simply
doesn't achieve what I want to do.
I would like to add it to the parent that holds list view items. I
have parent available in adapter's GetView method. When I tried to do
that got error message telling me that addView is not allowed
operation.


The parent here is the list view itself. You don't need to add views to 
parent view in getView, as it's done for you (after getView returns).



2) I tried to keep refererence to original adapter object and use that
one when doing notifyDataSetChanged();  and I ended up with the same
ClassCastException error.


Can you post some relevant parts of the code, along with logcat output?


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-14 Thread bobetko
Thanks, I tried this. I got ClassCastException when
adapter.notifyDataSetChanged() was executed.
Thanks anyway.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-14 Thread bobetko
Kostya, I tried to do as you suggested. and non of it worked.
1) Don't want to add my header view into list's parent. It simply
doesn't achieve what I want to do.
I would like to add it to the parent that holds list view items. I
have parent available in adapter's GetView method. When I tried to do
that got error message telling me that addView is not allowed
operation.
2) I tried to keep refererence to original adapter object and use that
one when doing notifyDataSetChanged();  and I ended up with the same
ClassCastException error.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread blindfold
http://stackoverflow.com/questions/4393775/android-classcastexception-when-adding-a-header-view-to-expandablelistview
helped me out with addHeaderView() and the infamous
ClassCastException.

Basically you do TopSearch.setLayoutParams(new
ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT,
ListView.LayoutParams.WRAP_CONTENT)); right before
lv.addHeaderView(TopSearch);

Regards

On Dec 10, 5:37 pm, bobetko  wrote:
> I have added a view to the header of my ListView by following way:
>
>         ListView lv = (ListView)getListView();
>         View TopSearch =  (View) View.inflate(this, R.layout.search,
> null);
>         lv.addHeaderView(TopSearch, null, false);
>
> And everything is fine until I make changes to data adapter and then
> try to execute:
>
>        adapter.notifyDataSetChanged();
>
> This always crashes my application giving me following error:
>
> "java.lang.ClassCastException: android.widget.HeaderViewListAdapter"
>
> If I don't add header view to my list view, then everything works fine
> with no errors
> Any suggestions?
>
> Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread bobetko
Thank you very much Kostya.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread bobetko
Yes. myAdapter implements Fliterable

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread Mark Murphy
You can also call getWrappedAdapter() on the HeaderViewListAdapter to
get the underlying adapter, casting it to Filterable or whatever.

On Fri, Dec 10, 2010 at 1:51 PM, Kostya Vasilyev  wrote:
> Bob,
>
> The error is caused by addHeaderView wrapping your ListView adapter.
>
> public void addHeaderView (View v)
> Since: API Level 1
>
> Add a fixed view to appear at the top of the list. If addHeaderView is
> called more than once, the views will appear in the order they were added.
> Views added using this call can take focus if they want.
>
> NOTE: Call this before calling setAdapter. This is so ListView can wrap the
> supplied cursor with one that will also account for header and footer views.
>
> So if you call getAdapter right after calling setAdapter (and in case there
> was a prior addHeaderView), you will not get back the same object, you will
> get a HeaderViewListAdapter. It's actually in your logcat.
>
> Your adapter implements Filterable, but android.widget.HeaderViewListAdapter
> does not. Hence the class cast exception.
>
> I can think of two ways to fix this:
>
> - Do not use addHeaderView, instead add the header layout into the
> ListView's parent, positioned right above.
>
> - Might also work: keep a reference to your original adapter object, the one
> that implements Filterable, and use that object reference for casting to
> Filterable.
>
> -- Kostya
>
> 10.12.2010 21:39, TreKing пишет:
>
> On Fri, Dec 10, 2010 at 12:36 PM, bobetko  wrote:
>>
>> I call setHeaderView in onCreate, before I set myAdapter.
>
> OK, that eliminates that.
>>
>> ((Filterable) adapter).getFilter().filter(s);
>
> Does your adapter extend Filterable?
> -
> TreKing - Chicago transit tracking app for Android-powered devices
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
> --
> Kostya Vasilyev -- WiFi Manager + pretty widget --
> http://kmansoft.wordpress.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread Kostya Vasilyev

Bob,

The error is caused by addHeaderView wrapping your ListView adapter.


public void addHeaderView (View v)
Since: API Level 1

Add a fixed view to appear at the top of the list. If addHeaderView is 
called more than once, the views will appear in the order they were 
added. Views added using this call can take focus if they want.


NOTE: Call this before calling setAdapter. *This is so ListView can 
wrap the supplied cursor with one that will also account for header 
and footer views.*


So if you call getAdapter right after calling setAdapter (and in case 
there was a prior addHeaderView), you will not get back the same object, 
you will get a HeaderViewListAdapter. It's actually in your logcat.


Your adapter implements Filterable, but 
android.widget.HeaderViewListAdapter does not. Hence the class cast 
exception.


I can think of two ways to fix this:

- Do not use addHeaderView, instead add the header layout into the 
ListView's parent, positioned right above.


- Might also work: keep a reference to your original adapter object, the 
one that implements Filterable, and use that object reference for 
casting to Filterable.


-- Kostya

10.12.2010 21:39, TreKing ?:
On Fri, Dec 10, 2010 at 12:36 PM, bobetko > wrote:


I call setHeaderView in onCreate, before I set myAdapter.


OK, that eliminates that.

((Filterable) adapter).getFilter().filter(s);


Does your adapter extend Filterable?

-
TreKing  - Chicago 
transit tracking app for Android-powered devices


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en 



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread TreKing
On Fri, Dec 10, 2010 at 12:36 PM, bobetko  wrote:

> I call setHeaderView in onCreate, before I set myAdapter.


OK, that eliminates that.

((Filterable) adapter).getFilter().filter(s);


Does your adapter extend Filterable?

-
TreKing  - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread bobetko
I call setHeaderView in onCreate, before I set myAdapter.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread bobetko
line 130 is this:

((Filterable) adapter).getFilter().filter(s);

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread John
This looks like the problem here. Is that your code? What is line 130?

On Dec 10, 10:37 am, bobetko  wrote:
> com.sanantonio.cvb.PropertyList$1.onTextChanged(PropertyList.java:130)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread TreKing
On Fri, Dec 10, 2010 at 12:01 PM, bobetko  wrote:

> I set it in activity's OnCreate method with
>
>myAdapter = new myBaseAdapter(this);
>lv.setAdapter(myAdapter);
>

And where do you call setHeaderView in relation to this?

-
TreKing  - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread bobetko
I set it in activity's OnCreate method with

myAdapter = new myBaseAdapter(this);
lv.setAdapter(myAdapter);

and myAdapter is declared as
private myBaseAdapter myAdapter;
and visible in all activity methods.

Then (maybe important)
I have text watcher, which onTextChanged execute:

final BaseAdapter adapter = (BaseAdapter)
lv.getAdapter();
((Filterable) adapter).getFilter().filter(s);  //
s is a search string

myBaseAdapter implements Filterable which execute
notifyDataSetChanged() when new filter is applied.

As I said before, the code doesn't produce any error if I comment 2
lines where I add header view.

Thanks,

On Dec 10, 11:42 am, TreKing  wrote:
> On Fri, Dec 10, 2010 at 10:37 AM, bobetko  wrote:
> > Any suggestions?
>
> When do you set your adapter?
>
> --- 
> --
> TreKing  - Chicago
> transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: HeaderView in ListView causing ClassCastException

2010-12-10 Thread bobetko
Here it is:

12-10 11:35:28.111: ERROR/AndroidRuntime(25364): FATAL EXCEPTION: main
12-10 11:35:28.111: ERROR/AndroidRuntime(25364):
java.lang.ClassCastException: android.widget.HeaderViewListAdapter
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
com.sanantonio.cvb.PropertyList$1.onTextChanged(PropertyList.java:130)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.widget.TextView.sendOnTextChanged(TextView.java:6131)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.widget.TextView.handleTextChanged(TextView.java:6172)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:
6316)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:
889)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:
502)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:
409)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:
28)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:
583)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:
384)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:
292)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
com.android.internal.view.IInputConnectionWrapper
$MyHandler.handleMessage(IInputConnectionWrapper.java:73)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.os.Handler.dispatchMessage(Handler.java:99)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.os.Looper.loop(Looper.java:123)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
android.app.ActivityThread.main(ActivityThread.java:4627)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
java.lang.reflect.Method.invokeNative(Native Method)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
java.lang.reflect.Method.invoke(Method.java:521)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:858)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-10 11:35:28.111: ERROR/AndroidRuntime(25364): at
dalvik.system.NativeStart.main(Native Method)

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en