带有 NumberPicker 子项的 ExpandableListView 不会展开
ExpandableListView with NumberPicker child will not expand
我是 android 开发的新手,我有一个可扩展的列表视图,其中有一个数字选择器作为子项。当我点击该组时,该组不会展开。这是我目前拥有的:
主要布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/leadTrackerExpand"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ExpandableListView
android:id="@+id/tracklist"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ExpandableListView>
</LinearLayout>
组布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ltDetails"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/ltGroupHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</LinearLayout>
子布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ltDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<NumberPicker
android:id="@+id/pickNum"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>
适配器
public class LeadTrackerAdapter extends BaseExpandableListAdapter {
private Activity context;
private String[] ltHeader;
public LeadTrackerAdapter(Activity context, String[] ltHeader){
this.context = context;
this.ltHeader = ltHeader;
}
@Override
public int getGroupCount() {
return ltHeader.length;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getGroup(int groupPosition) {
return ltHeader[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View header = convertView;
String trackHeaderName = (String) getGroup(groupPosition);
if (header == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
header = inflater.inflate(R.layout.lt_group,
null);
TextView item = (TextView) header.findViewById(R.id.ltGroupHeader);
// item.setTypeface(null, Typeface.BOLD);
item.setText(trackHeaderName);
}
return header;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
View row = convertView;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.lt_details,
null);
NumberPicker numPicker = (NumberPicker)row.findViewById(R.id.pickNum);
numPicker.setMaxValue(100);
numPicker.setMinValue(0);
numPicker.setValue(0);
return row;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
}
Activity class
public class LeadTrackerActivity extends ExpandableListActivity {
String[] groupList;
ExpandableListView ltList;
LeadTrackerAdapter ltAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ltList = getExpandableListView();
ltList.setGroupIndicator(null);
ltList.setClickable(true);
populateGroupList();
ltAdapter = new LeadTrackerAdapter(LeadTrackerActivity.this, groupList);
setListAdapter(ltAdapter);
ltList.setOnGroupClickListener(new OnGroupClickListener(){
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
(parent.isGroupExpanded(groupPosition)));
if (parent.isGroupExpanded(groupPosition)) {
parent.collapseGroup(groupPosition);
} else {
parent.expandGroup(groupPosition);
}
return true;
}
});
}
private void populateGroupList() {
groupList = new String[]{"Follow-up Calls", "Team Building Leads", "Recruit Leads",
"Interviews", "Sells"};
}
}
在查看其他使用 ExpandableListView 并尝试一些东西的帖子后,终于找到了答案。就我而言。我需要将 children 计数更改为 1,这是我想要显示的数字选择器的数量。如下图
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return 1;
}
我是 android 开发的新手,我有一个可扩展的列表视图,其中有一个数字选择器作为子项。当我点击该组时,该组不会展开。这是我目前拥有的:
主要布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/leadTrackerExpand"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ExpandableListView
android:id="@+id/tracklist"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ExpandableListView>
</LinearLayout>
组布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ltDetails"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/ltGroupHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</LinearLayout>
子布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ltDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<NumberPicker
android:id="@+id/pickNum"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>
适配器
public class LeadTrackerAdapter extends BaseExpandableListAdapter {
private Activity context;
private String[] ltHeader;
public LeadTrackerAdapter(Activity context, String[] ltHeader){
this.context = context;
this.ltHeader = ltHeader;
}
@Override
public int getGroupCount() {
return ltHeader.length;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getGroup(int groupPosition) {
return ltHeader[groupPosition];
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View header = convertView;
String trackHeaderName = (String) getGroup(groupPosition);
if (header == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
header = inflater.inflate(R.layout.lt_group,
null);
TextView item = (TextView) header.findViewById(R.id.ltGroupHeader);
// item.setTypeface(null, Typeface.BOLD);
item.setText(trackHeaderName);
}
return header;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
View row = convertView;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.lt_details,
null);
NumberPicker numPicker = (NumberPicker)row.findViewById(R.id.pickNum);
numPicker.setMaxValue(100);
numPicker.setMinValue(0);
numPicker.setValue(0);
return row;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
}
Activity class
public class LeadTrackerActivity extends ExpandableListActivity {
String[] groupList;
ExpandableListView ltList;
LeadTrackerAdapter ltAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ltList = getExpandableListView();
ltList.setGroupIndicator(null);
ltList.setClickable(true);
populateGroupList();
ltAdapter = new LeadTrackerAdapter(LeadTrackerActivity.this, groupList);
setListAdapter(ltAdapter);
ltList.setOnGroupClickListener(new OnGroupClickListener(){
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
(parent.isGroupExpanded(groupPosition)));
if (parent.isGroupExpanded(groupPosition)) {
parent.collapseGroup(groupPosition);
} else {
parent.expandGroup(groupPosition);
}
return true;
}
});
}
private void populateGroupList() {
groupList = new String[]{"Follow-up Calls", "Team Building Leads", "Recruit Leads",
"Interviews", "Sells"};
}
}
在查看其他使用 ExpandableListView 并尝试一些东西的帖子后,终于找到了答案。就我而言。我需要将 children 计数更改为 1,这是我想要显示的数字选择器的数量。如下图
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return 1;
}