我们可以在ListView中使用ExpandableListView,这样我就可以先拥有组级别,然后再有子项目。 只有ExpandableListView是组和孩子,我想有一个ExpandableListView里面的ListView。 尝试使用开源的TreeView,但无法获得ExpandableListView的所有功能。 期待您的回复。 谢谢。可扩展的ListView可以在ListView内部
0
A
回答
2
ExpandableListView本身的ListView,你不能使用ExpandableListView里面的ListView ...
0
但是你可以实现无ListView控件需要的相同的功能。这是相同的代码。
ExpandableListView适配器代码:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
/**
* Holds the mapping details
*/
Mapdetail mMapDetials = new Mapdetail();
/**
* Holds the contest
*/
private Context mContext;
/**
* Holds tehe xpandable list VIew
*/
private ExpandableListView mExpandableListView;
/**
* Holds the details for the cards
*/
private List<com.sourcebits.sfc.activity.GroupEntity> mGroupCollection;
/**
* Holds the status whether its expanded or not
*/
private int[] groupStatus;
public ExpandableListAdapter(Context pContext,
ExpandableListView pExpandableListView,
List<com.sourcebits.sfc.activity.GroupEntity> mGroupCollection2) {
mContext = pContext;
mGroupCollection = mGroupCollection2;
mExpandableListView = pExpandableListView;
groupStatus = new int[mGroupCollection.size()];
setListEvent();
}
/**
* Sets the event listeners
*/
private void setListEvent() {
mExpandableListView
.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int arg0) {
groupStatus[arg0] = 1;
}
});
mExpandableListView
.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int arg0) {
groupStatus[arg0] = 0;
}
});
}
@Override
public String getChild(int arg0, int arg1) {
return mGroupCollection.get(arg0).GroupItemCollection.get(arg1).Name;
}
@Override
public long getChildId(int arg0, int arg1) {
return 0;
}
@Override
public View getChildView(final int arg0, final int arg1, boolean arg2,
View arg3, ViewGroup arg4) {
ChildHolder childHolder;
if (arg3 == null) {
arg3 = LayoutInflater.from(mContext).inflate(
R.layout.list_group_item, null);
childHolder = new ChildHolder();
childHolder.title = (TextView) arg3.findViewById(R.id.item_title);
childHolder.background = (ImageView) arg3
.findViewById(R.id.background);
arg3.setTag(childHolder);
} else {
childHolder = (ChildHolder) arg3.getTag();
}
if (arg1 == 0) {
childHolder.background.setBackgroundResource(R.drawable.list_top);
} else {
childHolder.background
.setBackgroundResource(R.drawable.list_bottom);
}
childHolder.title.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mMapDetials.setmLanguageIndex(mGroupCollection.get(arg0).GroupItemCollection
.get(arg1).Name);
startNextActivity();
}
});
childHolder.title
.setText(mGroupCollection.get(arg0).GroupItemCollection
.get(arg1).Name);
return arg3;
}
@Override
public int getChildrenCount(int arg0) {
return mGroupCollection.get(arg0).GroupItemCollection.size();
}
@Override
public Object getGroup(int arg0) {
return mGroupCollection.get(arg0);
}
@Override
public int getGroupCount() {
return mGroupCollection.size();
}
@Override
public long getGroupId(int arg0) {
return arg0;
}
@Override
public View getGroupView(final int arg0, boolean arg1, View arg2,
ViewGroup arg3) {
GroupHolder groupHolder;
if (arg2 == null) {
arg2 = LayoutInflater.from(mContext).inflate(R.layout.list_group,
null);
groupHolder = new GroupHolder();
groupHolder.img = (ImageView) arg2.findViewById(R.id.tag_img);
groupHolder.title = (TextView) arg2.findViewById(R.id.group_title);
arg2.setTag(groupHolder);
} else {
groupHolder = (GroupHolder) arg2.getTag();
}
if (groupStatus[arg0] == 0) {
groupHolder.img.setImageResource(R.drawable.icon_expand);
} else {
mMapDetials.setTrainingPointIndex(mGroupCollection.get(arg0).Name);
groupHolder.img.setImageResource(R.drawable.icon_collapse);
}
groupHolder.img.setTag("NotClicked");
if (mGroupCollection.get(arg0).GroupItemCollection.size() == 0) {
groupHolder.img.setImageResource(R.drawable.arrow);
mMapDetials.setmLanguageIndex("English");
groupHolder.img.setTag("Clicked");
groupHolder.img.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v.getTag().toString().equals("Clicked")) {
mMapDetials.setTrainingPointIndex(mGroupCollection
.get(arg0).Name);
startNextActivity();
return false;
}
return false;
}
});
}
groupHolder.title.setText(mGroupCollection.get(arg0).Name);
return arg2;
}
/**
* Holds the view of the parent
*
* @author Gautam Balasubramanian
*
*/
class GroupHolder {
ImageView img;
TextView title;
}
/**
* ChildHolder class view of the child view
*
* @author Gautam Balasubramanian
*
*/
class ChildHolder {
TextView title;
ImageView background;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
void startNextActivity() {
Intent intent = new Intent(mContext, GeneralInfo.class);
mMapDetials.toString();
Bundle extras = new Bundle();
extras.putSerializable("values", mMapDetials);
intent.putExtras(extras);
mContext.startActivity(intent);
}
}
代码从activty拨打:
private void initPage() {
mExpandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
mExpandableListView.setCacheColorHint(0);
ExpandableListAdapterforProducts adapter = new ExpandableListAdapterforProducts(
Products.this, mExpandableListView, mGroupCollection);
mExpandableListView.setAdapter(adapter);
ColorDrawable sage = new ColorDrawable(this.getResources().getColor(
R.color.sage));
mExpandableListView.setDivider(sage);
mExpandableListView.setDividerHeight(1);
}
Initailisation值,
mySQLiteAdapter = new SqliteAdapterForProducts(this);
mySQLiteAdapter.openToRead();
mCursor = mySQLiteAdapter.queueProducts();
Log.v("", mCursor.getCount() + "is the count");
mCursor.moveToFirst();
mGroupCollection = new ArrayList<GroupEntity>();
for (int i = 0; i < mCursor.getCount(); i++) {
GroupEntity groupEntity = new GroupEntity();
groupEntity.Name = mCursor.getString(1) + " "
+ mCursor.getString(2);
String languages[] = mCursor.getString(3).toString().split(",");
if (languages.length > 1) {
for (int j = 0; j < languages.length; j++) {
GroupItemEntity groupItemEntity = groupEntity.new GroupItemEntity();
groupItemEntity.Name = languages[j];
groupEntity.GroupItemCollection.add(groupItemEntity);
}
}
mCursor.moveToNext();
mGroupCollection.add(groupEntity);
}
mCursor.close();
mySQLiteAdapter.close();
以上的东西为我工作。你可以尝试一下。
相关问题
- 1. ListView的可扩展头视图
- 2. 我得到一个可扩展的ListView
- 3. 如何使我的嵌套的ListView可折叠和可扩展
- 4. Expandable ListView不扩展
- 5. Android onChildClickListener可展开ListView
- 6. 的Android扩展的ListView
- 7. 我如何可以访问内部存储,以列出的ListView
- 8. WPF - 使用可选和可选ListViewItems扩展ListView
- 9. 如何动画扩展ListView?
- 10. 点击动画扩展listview
- 11. 如何扩展一个listview?
- 12. Android类扩展listview错误
- 13. LIstView内部的ToggleButton
- 14. 可扩展的ListView与自定义对象
- 15. Android - 仅有1个可扩展项目的ListView
- 16. 如何将字符串放入可扩展listView的edittext中?
- 17. 可扩展列表查看具有子列表的示例listView
- 18. Windows窗体中的可扩展组ListView控件
- 19. 扩展Moose类以使内部可以使用不同的类
- 20. 可以帮我解决ListView?
- 21. 可扩展ListView按年/月分组项目
- 22. 是否可以在Java中扩展非静态内部类?
- 23. 是否有可能在android中的可扩展列表视图的子视图内实现listview?
- 24. ListView可索引?
- 25. 展开ListView和可点击图片
- 26. 的ListView上的程序扩展开始
- 27. 你可以把可扩展列表可扩展列表中
- 28. Listview中的内容是不可见的
- 29. tabhost内的不可触摸的ListView
- 30. 是否可以在ListView中实现ItemTemplate?
我不同意你的条款,你想ListView内的可扩展列表视图,因为**可扩展列表查看本身的列表视图**与特定项目展开每当你点击它。 – 2012-02-09 05:53:22
最初使Expandalbe ListView的所有项目都折叠起来,每当用户点击[onChildClickListener](http://developer.android.com/reference/android/widget/ExpandableListView.OnChildClickListener.html)时展开它。 – 2012-02-09 05:54:48
查看这个例子,我正在说什么:http://coderzheaven.com/2011/04/expandable-listview-in-android-using-simpleexpandablelistadapter-a-simple-example/ – 2012-02-09 05:57:43