I just check this SO link to add an object at the top of the adapter.
Here is the code which I found that to add an object to at the top of the adapter:
yourAdapter.insert(object, 0);
But in my case the data type of object is different from the data type of adapter. So I am getting following error:
Wrong 1st argument type. required.......
So I decided to cast the object and then try to insert:
adapter.insert((OneOnOneMessage)messageList, 0);
But no luck was with me and started getting following run time error:
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.mics.models.OneOnOneMessage
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at com.mics.activities.SingleChatActivity$2.onClick(SingleChatActivity.java:283)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at android.view.View.performClick(View.java:4448)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at android.view.View$PerformClick.run(View.java:18461)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at android.os.Looper.loop(Looper.java:136)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5072)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
03-08 14:55:43.933 6358-6358/com.dayoptions.chat W/System.err: at dalvik.system.NativeStart.main(Native Method)
I can add an object into the adapter by using following code:
adapter.addAll(messageList);
Using above line I am not getting any issue regarding 'wrong argument type'
or 'casting'
but I want to add the object at the top of the listview.