Je développe une application pour honeycomb, et j'ai mis des onglets dans la barre d'action, mais maintenant je ne sais pas comment mettre un ExpandableListView dans l'un des onglets, ou, dans un des fragments.Ajouter un ExpandableListView dans un fragment
1
A
Répondre
1
ExpandableListView n'est pas pris en charge dans les fragments pour le moment. Vous devez sous-classer Fragment pour cela. Si vous ne voulez pas de réinventer la roue, jetez un oeil à ceci: https://gist.github.com/1316903
1
Voici ce qui est fonctionne pour moi:
intérieur du fragment
private String[] categories;
private String[][] categoryItems;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
categories = getResources().getStringArray(R.array.videos_curriculum);
String[] category1 = getResources().getStringArray(R.array.video_category1);
String[] category2 = getResources().getStringArray(R.array.video_category2);
String[] category3 = getResources().getStringArray(R.array.video_category3);
categoryItems = new String[][]{category1, category2, category3};
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
listView = (ExpandableListView) view.findViewById(R.id.expListView);
listView.setAdapter(new VideoGroupsListAdapter(categories, categoryItems));
listView.setGroupIndicator(null); // I don't need group indicator on left
}
, classe interne:
public class VideoGroupsListAdapter extends BaseExpandableListAdapter {
private final LayoutInflater inflater;
private String[] groups;
private String[][] children;
public VideoGroupsListAdapter(String[] groups, String[][] children) {
this.groups = groups;
this.children = children;
inflater = LayoutInflater.from(getActivity());
}
@Override
public int getGroupCount() {
return groups.length;
}
@Override
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.new_video_header, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.headerTitleTxt);
holder.icon = (TextView) convertView.findViewById(R.id.headerIconTxt);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getGroup(groupPosition).toString());
if (isExpanded) {
holder.icon.setText(R.string.ic_down);
} else {
holder.icon.setText(R.string.ic_up);
}
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.new_video_list_item, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.titleTxt);
holder.icon = (TextView) convertView.findViewById(R.id.watchedIconTxt);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getChild(groupPosition, childPosition).toString());
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
private class ViewHolder {
TextView text;
TextView icon;
}
}
new_videos_header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/ListItem.Header.Light"
android:gravity="center_vertical"
android:paddingLeft="@dimen/default_scr_side_padding"
android:paddingRight="@dimen/default_scr_side_padding"
>
<!--Title-->
<TextView
android:id="@+id/headerTitleTxt"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="8dip"
style="@style/HeaderTitle.Dark"
/>
<!--Right Icon-->
<TextView
android:id="@+id/headerIconTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ic_up"
/>
</LinearLayout>
Questions connexes
- 1. Ajouter un fragment dans un fragment (fragment imbriqué)
- 2. ExpandableListView ne pas montrer dans TabHost dans Fragment
- 3. Comment ajouter un DialogFragment dans un Fragment normal?
- 4. Deux ExpandableListView dans un ScrollView
- 5. Android - Ajouter du code à un fragment
- 6. ExpandableListView avec un EditText
- 7. Remplir dynamiquement un expandableListView
- 8. Problème mettant un fragment dans un autre fragment
- 9. Ajouter ExpandableListView à un onglet avec d'autres éléments
- 10. fragment: créer différentes vues dans un fragment
- 11. Fragment de mappe V2 dans un fragment
- 12. Grille dans un fragment
- 13. setContentView dans un fragment
- 14. ViewPager dans un fragment
- 15. Comment puis-je ajouter 3 HorizontalScrollViews dans un fragment?
- 16. Ajouter une vue à un fragment dynamiquement dans Android?
- 17. Plusieurs dispositions pour un ExpandableListView
- 18. remplir un expandableListView avec arrayLists
- 19. Est-il possible d'avoir un ListView dans un Fragment - ou un ListFragment dans un Fragment?
- 20. Android: Comment faire un clic enfant dans ExpandableListView
- 21. Utiliser TelephonyManager dans un fragment?
- 22. WebView dans un fragment (android.support.v4)
- 23. Android - SensorEventListenr dans un fragment
- 24. Tiroir coulissant dans un fragment
- 25. charger RetainFragment dans un fragment
- 26. Ajouter des mises en page à un fragment programaticallycaly
- 27. Ajouter un ID de fragment à une redirection Zend
- 28. Comment remplacer un fragment avec un fragment de viewpager
- 29. Android Ajouter dynamiquement un fragment avec des sous-vues
- 30. Comment démarrer un fragment/une activité dans Fragment?