Dynamically update list element height in ListView
I have a list. When you click on element, it becomes selected, and should be expanded vertically to displat some more data.
I am trying to accomplish this by adding to each element's layout "Details" view which is hidden by dafault and is set to VISIBLE onClick.
The only problem that the height of element isn't changed. If I try to it like this:
holder.line_view
.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, dip(
convertView.getContext(), 30)));
then I get unknown exception. Just
holder.details_pane.setVisibility(View.VISIBLE);
doesn't work, the size isn't changed.
Please advise.
Layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/line_view">
<TextView
android:id="@+id/desc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Description" />
<TextView
android:text="LALALA"
android:id="@+id/detailed_desc"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
In adapter I try:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
switch (getItemViewType(position)) {
case TYPE_ITEM_EXPANDED:
holder.detail开发者_StackOverflows_pane.setVisibility(View.VISIBLE);
...
case TYPE_ITEM_NORMAL:
holder.details_pane.setVisibility(View.GONE);
}
"doesn't work, the size isn't changed"
something to try if you allow your view to be rotated: make your view redraw itself and see if the row is bigger.
It might be that you just need to invalidate the listview so that it redraws. Possibly invalidate the row.
maybe it's even as easy as calling notifyDataSetChanged(); on your custom listview adapter
I have no idea about the issue of you code. but you should try this
com.android.widget.ExpandableListView
com.android.widget.ExpandableListAdapter
this is designed for your requirement and shipped with the OS
精彩评论