我一直在寻找将expandablelistview添加到片段的方法,我已经阅读了文档,但仍然对如何做到这一点感到困惑。所以我有两个问题:
有没有办法可以将这个:http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/变成片段?
在下面给出的代码中,我尝试将android:groupIndicator
的指标添加到expandablelistview,但它没有显示。这是代码,有没有办法直接添加指标?
public class Services extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.services_layout, null);
ExpandableListView elv = (ExpandableListView) v.findViewById(R.id.list);
elv.setAdapter(new SavedTabsListAdapter());
return v;
}
public class SavedTabsListAdapter extends BaseExpandableListAdapter {
private String[] groups = { "Class 13", "Class 12", "Class 11", "Class 10", "Class 9" };
private String[][] children = {
{ "Blue", "Green" },
{ "Orange", "Purple", "Black" },
{ "White", "Brown" },
{ "Golden", "Silver", "Red" },
{ "Pink", "Gray", "Yellow" }
};
@Override
public int getGroupCount() {
return groups.length;
}
@Override
public int getChildrenCount(int i) {
return children[i].length;
}
@Override
public Object getGroup(int i) {
return groups[i];
}
@Override
public Object getChild(int i, int i1) {
return children[i][i1];
}
@Override
public long getGroupId(int i) {
return i;
}
@Override
public long getChildId(int i, int i1) {
return i1;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
TextView textView = new TextView(Services.this.getActivity());
textView.setText(getGroup(i).toString());
textView.setBackgroundColor(0xFF3F9FE0);
return textView;
}
@Override
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
TextView textView = new TextView(Services.this.getActivity());
textView.setText(getChild(i, i1).toString());
return textView;
}
@Override
public boolean isChildSelectable(int i, int i1) {
return true;
}
} }
答案 0 :(得分:1)
您可以使用类似下面的内容。为我工作:
Picasso.with(activityContext).load(thumbnailurl)
.into(imageViewReference);
答案 1 :(得分:0)
getActivity()
。android:groupIndicator="@drawable/indicator_pic"
中或以编程方式expanadableListView.setGroupIndicator(R.drawable.your_pic);
。类似的东西是here。随意问我。答案 2 :(得分:0)
您可能需要查看the example source code。该类使用您在片段内讨论的功能。