ListView 내에 ExpandableListView를 포함하여 그룹 수준의 자식 항목을 가질 수 있습니까? ExpandableListView 만 그룹 및 하위입니다. Listable 내부에 ExpandableListView가 있어야합니다. 오픈 소스 TreeView를 사용해 보았지만 ExpandableListView의 모든 기능을 구체적으로 가져올 수 없습니다. 답장을 기다리겠습니다. 덕분에 . 자체의 ListView가 ExpandableListViewExpandable ListView를 ListView 내부에 둘 수 있음
0
A
답변
2
, 당신은 ListView에 내부 ExpandableListView를 사용할 수 없습니다 ...
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. Expandable listview 새로 고침
- 2. Expandable ListView
- 3. 동일한 XML 파일의 ListView 및 Expandable listview
- 4. Expandable ListView 어린이가 표시되지 않음
- 5. 갤러리 내부에 ListView 포함하기
- 6. 다른 ListView 내에서 ListView를 사용할 수 있습니까?
- 7. ListView android : 코드가 비어 있음
- 8. Button 이벤트가 UIWebView 내부에 있음
- 9. 루스 생성자가 변수 내부에 있음
- 10. vi 편집기 내부에 밑줄이 있음
- 11. 동적으로 DefaultButton UpdatePanel 내부에 있음
- 12. JQueryMobile : ListView 내부에 Button 추가하기
- 13. ListView 내부에 LinearLayout 넣기 (안드로이드)
- 14. listView를 채울 수 없습니까?
- 15. ListView 항목을 변경하고 ListView를 업데이트 할 수 있습니까?
- 16. 다른 ListView 안에 ListView를 배치하는 방법 ....?
- 17. TabHost에 Listview를 넣는 데 문제가 있음 (보기가 아닌 활동으로)
- 18. AdView를 180px 너비로 축소하는 LinearLayout 내부에 AdView를 둘 수 있습니까
- 19. 하나의 포틀릿 내부에 여러 페이지가 있음
- 20. Adcontrol 피벗 항목 템플릿 내부에 InvalidCastException이 있음
- 21. 컨테이너 클래스 내부에 많은 변수가 있음
- 22. ListView를
- 23. ListView ArrayAdapter, Row 내부에 자식을 숨기고 있습니까?
- 24. ListView 행 높이를 콘텐츠 내부에 맞추려면 어떻게합니까?
- 25. Expandable ListView에서 뷰의 값을 유지할 수 없습니다.
- 26. Expandable 애니메이션 메뉴
- 27. Expandable div Jquery 사용하기
- 28. JavaScript expandable treeview lightweight
- 29. Expandable div like functionality
- 30. ListView onItemClick가 응답하지 않는 경우가 있음
** 확장 가능한 목록보기 자체는 클릭 할 때마다 특정 항목이 포함 된 목록보기 **가 확장되므로 사용자가 확장 가능한 목록보기를 ListView에서 원하는 조건에 동의하지 않습니다. –
처음에 ExpandableListView의 모든 항목을 축소 된 것으로 만들고, 사용자가 [onChildClickListener] (http://developer.android.com/reference/android/widget/ExpandableListView.OnChildClickListener.html)를 클릭 할 때마다 확장하십시오. –
내가 무슨 말을하는지이 예제를 확인하십시오 : http://coderzheaven.com/2011/04/expandable-listview-in-android-using-simpleexpandablelistadapter-a-simple-example/ –