我正在使用 ExpandableListFragment 在 TabHost 片段内创建 ExpandableList
我从这里得到了 ExpandableListFragment 的代码https://gist.github.com/1316903
它似乎工作正常,除了我不知道如何更改文本颜色。
我的实现看起来像这样
public class LocalListFragment extends ExpandableListFragment {
private static final String NAME = "NAME";
private static final String IS_EVEN = "IS_EVEN";
private ArrayList<String> mGroups;
private ArrayList<ArrayList<Song>> mChildren;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
// Set up our adapter
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < 10; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "GROUP" + i);
//curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < 5; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(IS_EVEN, "Child " + j);
}
childData.add(children);
}
mAdapter = new SimpleExpandableListAdapter(
getActivity().getApplicationContext(),
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 },
childData,
android.R.layout.simple_expandable_list_item_2,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 }
);
//TextView tv = (TextView)getActivity().findViewById(android.R.id.text1);
//tv.setTextColor(0xffff0000);
setListAdapter(mAdapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Log.i("TAG", "Item selected");
}
}
我的猜测是“new int[] { android.R.id.text1, android.R.id.text2 },”行与它有很大关系,但我对此有点困惑。
有人可以帮忙吗?我需要创建新的 TextView id 并指定 textColor 吗?我试过但无法弄清楚。谢谢。