我有一個ExpandleListView和一些TextViews和圖像。 克隆後,我想showTextView作爲孩子,並隱藏GroupView中的另一個TextView。不幸的是,列表顯示正確,但點擊後的項目根本不擴展,事件當我設置OnGroupClickListener並嘗試調試它時,斷點不會觸發。Expandable ListView不擴展
XML
<<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/notificationItem"
android:orientation="vertical"
android:padding="15sp"
android:animateLayoutChanges="true"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_gravity="start"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/notificationLogo"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:clickable="false"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20sp"
android:paddingLeft="10sp"
android:layout_toRightOf="@+id/notificationLogo"
android:orientation="vertical"
android:id="@+id/headerContent">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/date"/>
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/eventName"/>
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/shortDescription"
android:ellipsize="end"
android:maxLines="2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fullDescription"
android:layout_gravity="center"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/downButton"
android:layout_centerInParent="true"
android:layout_below="@+id/headerContent"
android:background="@android:color/transparent"/>
</RelativeLayout>
</LinearLayout>
適配器類
public class NotificationAdapter extends BaseExpandableListAdapter {
private Context mContext;
private ViewHolder viewHolder;
final Typeface typeface;
List<MuseumNotification> notificationList;
public NotificationAdapter(Context context, List<MuseumNotification>notificationList){
mContext = context;
typeface = Typeface.createFromAsset(mContext.getAssets(),"fonts/fontawesome-webfont.ttf");
this.notificationList =notificationList;
}
@Override
public int getGroupCount() {
return notificationList.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public Object getGroup(int groupPosition) {
return notificationList.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return notificationList.get(groupPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if(viewHolder==null)
viewHolder =new ViewHolder();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.notification_item,parent,false);
viewHolder.notificationTitle=(TextView)convertView.findViewById(R.id.eventName);
viewHolder.shortDescription=(TextView)convertView.findViewById(R.id.shortDescription);
viewHolder.image_url=(ImageView)convertView.findViewById(R.id.notificationLogo);
viewHolder.notificationTitle.setText(notificationList.get(groupPosition).getTitle());
viewHolder.shortDescription.setText(notificationList.get(groupPosition).getText());
Glide.with(mContext)
.load("www.logo.png")
.fitCenter()
.into(viewHolder.image_url);
viewHolder.navDown=(Button)convertView.findViewById(R.id.downButton);
viewHolder.navDown.setTypeface(typeface);
viewHolder.navDown.setText(R.string.navDown);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.notification_item,parent,false);
viewHolder.description=(TextView)convertView.findViewById(R.id.fullDescription);
viewHolder.description.setText(notificationList.get(groupPosition).getText());
return convertView;
}
@Override
public void onGroupExpanded(int groupPosition) {
super.onGroupExpanded(groupPosition);
}
@Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
private class ViewHolder{
private TextView notificationTitle,description,shortDescription;
private ImageView image_url;
private Button navDown;
}
}
編輯:解決:在組項目i有一個可點擊的元件(按鈕)。它應該是不可聚焦的(android:focusable =「false」,XML)