我剛剛實現了可擴展列表視圖。我從[Expandablelistview] [1] 得到了參考所以我從上面的鏈接實現了Expandable Listview。 但問題是,我能夠在兒童組中實現一個textview。我想要在兒童組中添加三個textviewandroid可擴展列表視圖與四個textview在子組
所以我想在兒童組中添加四個textview請幫助我。其對我來說很重要veryn
我剛剛實現了可擴展列表視圖。我從[Expandablelistview] [1] 得到了參考所以我從上面的鏈接實現了Expandable Listview。 但問題是,我能夠在兒童組中實現一個textview。我想要在兒童組中添加三個textviewandroid可擴展列表視圖與四個textview在子組
所以我想在兒童組中添加四個textview請幫助我。其對我來說很重要veryn
更新兩個文件在演示 github.com/idunnololz/AnimatedExpandableListView
MainActivity:
package com.example.animatedexpandablelistview;
import java.util.ArrayList;
import java.util.List;
import com.idunnololz.widgets.AnimatedExpandableListView;
import com.idunnololz.widgets.AnimatedExpandableListView.AnimatedExpandableListAdapter;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.TextView;
/**
* This is an example usage of the AnimatedExpandableListView class.
*
* It is an activity that holds a listview which is populated with 100 groups
* where each group has from 1 to 100 children (so the first group will have one
* child, the second will have two children and so on...).
*/
public class MainActivity extends Activity {
private AnimatedExpandableListView listView;
private ExampleAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<GroupItem> items = new ArrayList<GroupItem>();
// Populate our list with groups and it's children
for(int i = 1; i < 10; i++) {
GroupItem item = new GroupItem();
item.title = "Group " + i;
ChildItem child = new ChildItem();
child.title = "Title " + i;
child.hint = "Hint"+ i;
child.subTitle="subtitle"+ i;
child.desc="Descrition"+ i;
item.items.add(child);
items.add(item);
}
adapter = new ExampleAdapter(this);
adapter.setData(items);
listView = (AnimatedExpandableListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
// In order to show animations, we need to use a custom click handler
// for our ExpandableListView.
listView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
// We call collapseGroupWithAnimation(int) and
// expandGroupWithAnimation(int) to animate group
// expansion/collapse.
if (listView.isGroupExpanded(groupPosition)) {
listView.collapseGroupWithAnimation(groupPosition);
} else {
listView.expandGroupWithAnimation(groupPosition);
}
return true;
}
});
}
private static class GroupItem {
String title;
List<ChildItem> items = new ArrayList<ChildItem>();
}
private static class ChildItem {
String title;
String hint;
String subTitle;
String desc;
}
private static class ChildHolder {
TextView title;
TextView hint;
TextView subTitle;
TextView desc;
}
private static class GroupHolder {
TextView title;
}
/**
* Adapter for our list of {@link GroupItem}s.
*/
private class ExampleAdapter extends AnimatedExpandableListAdapter {
private LayoutInflater inflater;
private List<GroupItem> items;
public ExampleAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
public void setData(List<GroupItem> items) {
this.items = items;
}
@Override
public ChildItem getChild(int groupPosition, int childPosition) {
return items.get(groupPosition).items.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getRealChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder holder;
ChildItem item = getChild(groupPosition, childPosition);
if (convertView == null) {
holder = new ChildHolder();
convertView = inflater.inflate(R.layout.list_item, parent, false);
holder.title = (TextView) convertView.findViewById(R.id.textTitle);
holder.hint = (TextView) convertView.findViewById(R.id.textHint);
holder.subTitle = (TextView) convertView.findViewById(R.id.textsubTitle);
holder.desc = (TextView) convertView.findViewById(R.id.textDesc);
convertView.setTag(holder);
} else {
holder = (ChildHolder) convertView.getTag();
}
holder.title.setText(item.title);
holder.hint.setText(item.hint);
holder.subTitle.setText(item.subTitle);
holder.desc.setText(item.desc);
return convertView;
}
@Override
public int getRealChildrenCount(int groupPosition) {
return items.get(groupPosition).items.size();
}
@Override
public GroupItem getGroup(int groupPosition) {
return items.get(groupPosition);
}
@Override
public int getGroupCount() {
return items.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
GroupHolder holder;
GroupItem item = getGroup(groupPosition);
if (convertView == null) {
holder = new GroupHolder();
convertView = inflater.inflate(R.layout.group_item, parent, false);
holder.title = (TextView) convertView.findViewById(R.id.textTitle);
convertView.setTag(holder);
} else {
holder = (GroupHolder) convertView.getTag();
}
holder.title.setText(item.title);
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
}
}
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="10dp"
android:paddingLeft="50dp">
<TextView
android:id="@+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textsubTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
wc! 當您的問題得到解決時,請不要忘記Upvote並接受答案:-) –
您是否創建了新項目或使用相同的演示? –
我認爲你需要更新您已擴展的自定義可擴展列表視圖。 仍然分享您的展開式列表視圖的代碼 –
請看看這個解決方案: http://stackoverflow.com/questions/32768040/multiple-textviews-in-expandablelistview-andoid –
只需給我半小時 –