Expand a list view when clicked on an element of it
I am be开发者_运维问答ginner in the android development, can any one tell me how to expand a list when I click on an element of it say an image icon.
This does it for me, due to privacy I can't write the whole code here
TextView desc = (TextView) v.findViewById(R.id.editText1);
ImageView icon = (ImageView) v.findViewById(R.id.listIcon);
if (desc.getVisibility() == View.VISIBLE) {
icon.getLayoutParams().height = heightIcon;
desc.setVisibility(View.GONE);
} else {
icon.getLayoutParams().height = LayoutParams.FILL_PARENT;
desc.setVisibility(View.VISIBLE);
}
Now when I click the icon, the text view placed below to it, becomes visible and thus has solved the question.
Take a look at ExpandableListView and ExpandableListAdapter
Here is the example code snippet to do it : ExpandableList1.java
You can even find it in your Android SDK folder
Drive:***\***\Android-sdk\samples\android-<apilevel>\ApiDemos\src\com\example\android\apis\view\ExpandableList1.java
精彩评论