Animating ListView Headers Using ClassCastException

I have a listview that stores the person’s communication history. I have one heading inside the list that acts as a message editor with edit text and a submit button. When the user types and presses the send button, messages are added to the communication list, and the editor becomes empty.

I want the user to click the submit button, the editor should become invisible, and the item should be added to the list. After that, the editor should gradually rise from the top, feeling that he is moving objects below.

I implemented the translation animation in the header, but what she does is space for her by pushing the elements down and then gradually fills the space that I don't want.

I used the negative field trick that is explained in this question , but this did not work for me. Since we cannot use layout options, others have AbsListView.LayoutParam for headers. I tried to set other parameters, but during the animation this gives me a ClassCastException. I tracked the exception and its code written inside the ListView, they try to pass these parameters using the AbsListView.LayoutParams method inside the clearRecycledState () method.

Or Is there a way to apply layout options that support the bullet in the listview header.

the code

public class PageListView extends ListView { private Application app; private CommListAdapter listAdapter; private MessageEditorHeader messageEditorHeader; private MessageItemLongClick mInterface; private Handler handler; public ProfilePageListView(Application app, MessageItemLongClick mInterface) { super(app); this.app = app; this.mInterface = mInterface; this.handler = new Handler(); setupView(); } public void applyData(ProfileData data){ listAdapter.applyData(data.getUser()); // some other business logic } private void setupView() { messageEditorHeader = new MessageEditorHeader(app); addHeaderView(messageEditorHeader); listAdapter = new CommListAdapter(app, mInterface); setAdapter(listAdapter); setDivider(null); setScrollingCacheEnabled(false); tAnimation = new TranslateAnimation(0.0f, 0.0f, -90.0f, 0.0f); tAnimation.setZAdjustment(-1); tAnimation.setDuration(1500); } // this gets called whenever the communication gets added to the listview. public void onNewCommunication(Communication lc) { listAdapter.onNewCommunication(); if(lc != null && lc.isOutgoing() && !lc.getType().isCall()){ getMessageEditor().startNewMessage(); messageEditorHeader.setVisibility(VISIBLE); // this is overriden method here I m toggling the height 1px and WRAP_CONTENT messageEditorHeader.startAnimation(tAnimation); } } // few more methods are there. } 

heres message editor code

 public class MessageEditorHeader extends RelativeLayout { private MessageEditor msgEditor; public MessageEditorHeader(AppteraApplication context) { super(context); msgEditor = new MessageEditor(context); // Its a relative layout containing edit text and the send button addView(msgEditor); } public MessageEditor getMsgEditor() { return msgEditor; } public void setProgress(int progress){ msgEditor.setProgress(progress); } @Override public void setVisibility(int visibility) { this.visibility = visibility; if (visibility == View.VISIBLE) { ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT, ListView.LayoutParams.WRAP_CONTENT); setLayoutParams(params); } else { ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT, 1); setLayoutParams(params); } } } 
+6
source share
1 answer

Have you thought about a different approach? Perhaps you can just put the editor at the top of the list, but off the screen, and then use smoothScrollToPosition to jump. in reality you are simply scrolling through the list, but the effect may be what you are looking for.

+1
source

Source: https://habr.com/ru/post/902823/


All Articles