[英]ExpandableListView Not Expanding?
您好,我一直在尝试在应用程序中使用可扩展列表视图。 问题是我可以获取parentList,但是在选择Parent Item时,子视图不会展开/显示,下面是我的代码。 谁能帮我解决这个问题,我已经尝试过xml中的可聚焦代码,但是没有用。
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="top"
android:gravity="top"
xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- <CheckBox
android:id="@+id/fee_term_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/sampleDimension10"
android:layout_weight="0"
/> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fee_schedule_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/sampleDimension"
android:orientation="horizontal">
<TextView
android:id="@+id/fee_schedule_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/sampleDimension10"
android:layout_weight="1"
android:paddingLeft="@dimen/sampleDimension"
android:text="term"
android:textColor="@color/black"
/>
<TextView
android:id="@+id/total_termfee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:text="Term Fee"
android:textColor="@color/black"
/>
</LinearLayout>
public class Expandable extends AppCompatActivity {
ExpandableListView expandableRecyclerview;
ExpandableAdapter expandableAdapter;
RecyclerView.LayoutManager layoutManager;
String feeMonthUrl = "http://35.196.219.109/webapi/newStudentPayment/getStudentPaymentDetails/155/4";
/*List<FeeMonth> feeMonths = null;
List<FeeTermDetailsData> dummyFeeType = null;
List<FeeTermDetailsData> feeTermDetailsDataList = null;*/
ArrayList<FeeMonth> feeMonths = new ArrayList<FeeMonth>();
List<StudentFeeScheduleData> feeScheduleData = new ArrayList<StudentFeeScheduleData>();
List<FeeTermDetailsData> feeTermDetailsDataList = new ArrayList<FeeTermDetailsData>();
ArrayList<ArrayList<FeeTermDetailsData>> dummyfeeType = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expandable_recyclerview);
expandableRecyclerview = (ExpandableListView) findViewById(R.id.expandable_recyclerview);
dummyfeeType = new ArrayList<ArrayList<FeeTermDetailsData>>();
Log.i("dummyyyyyy", dummyfeeType.toString());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(feeMonthUrl, null, new Response.Listener<JSONObject>() {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onResponse(JSONObject response) {
//p.dismiss();
try {
FeeMonth feeMonth = new FeeMonth();
JSONObject jsonObject = response.getJSONObject("response");
Log.i("mainObject", jsonObject.toString());
feeMonth.setYearId(jsonObject.getString("educationalYearId"));
Log.i("idddddd", jsonObject.getString("educationalYearId"));
JSONArray studentFeePlanwithAmount = jsonObject.getJSONArray("studentFeePlanWithAmounts");
Log.i("feePlanAmount", studentFeePlanwithAmount.toString());
dummyfeeType = new ArrayList<ArrayList<FeeTermDetailsData>>();
for (int i = 0; i < studentFeePlanwithAmount.length(); i++) {
JSONObject studentFeePlanObject = studentFeePlanwithAmount.getJSONObject(i);
JSONObject studentFeePlanAmountId = studentFeePlanObject.getJSONObject("studentFeePlanWithAmountId");
feeMonth.setStudentFeePlanWithAmountId(studentFeePlanAmountId.getInt("id"));
feeMonth.setName(studentFeePlanObject.getString("feePlanName"));
feeMonth.setTotalYearFee(studentFeePlanObject.getString("totalPayableAmount"));
Log.i("feeMonthhhhh", feeMonths.toString());
JSONArray feePlanSchedule = studentFeePlanObject.getJSONArray("studentFeePlanScheduleWithAmounts");
//studentFilterSchedule(7, feePlanSchedule);
for (int j = 0; j < feePlanSchedule.length(); j++) {
StudentFeeScheduleData studentFeeScheduleData = new StudentFeeScheduleData();
JSONObject termsObject = feePlanSchedule.getJSONObject(j);
JSONObject feePlanScheduleId = termsObject.getJSONObject("studentFeePlanScheduleWithAmountId");
studentFeeScheduleData.setFeePlanScheduleId(feePlanScheduleId.getInt("id"));
//JSONObject feePlanId = termsObject.getJSONObject("feePlanId");
//studentFeeScheduleData.setFeePlanId(feePlanId.getInt("id"));
studentFeeScheduleData.setTerms(termsObject.getString("feePlanScheduleName"));
studentFeeScheduleData.setTotalTermFee(termsObject.getDouble("duesFeeForSchedule"));
Log.i("feeMonthsss", feeMonth.toString());
JSONArray feePlanTypeDetailsArray = termsObject.getJSONArray("feeTypePerScheduleAmountList");
for (int k = 0; k < feePlanTypeDetailsArray.length(); k++) {
FeeTermDetailsData feeTermDetailsData = new FeeTermDetailsData();
JSONObject feeScheduleTypeDetails = feePlanTypeDetailsArray.getJSONObject(k);
JSONObject feeTypeId = feeScheduleTypeDetails.getJSONObject("feeTypePerScheduleAmountId");
feeTermDetailsData.setFeeTypeId(feeTypeId.getInt("id"));
JSONObject feeTypePlanScheduleId = termsObject.getJSONObject("studentFeePlanScheduleWithAmountId");
feeTermDetailsData.setFeePlanScheduleId(feeTypePlanScheduleId.getInt("id"));
feeTermDetailsData.setFeeTypeName(feeScheduleTypeDetails.getString("feeTypeName"));
feeTermDetailsData.setFeeTypeAmount(feeScheduleTypeDetails.getInt("amount"));
Log.i("feeTypeeee", feeTermDetailsDataList.toString());
Log.i("feeTypeeee",feeTermDetailsData.toString());
dummyfeeType.add(feeTermDetailsData);
Log.i("dummydataaa", jsonObject.toString());
}
feeScheduleData.add(studentFeeScheduleData);
}
/*JSONArray feePlanTypeDetailsArray= studentFeePlanObject.getJSONArray("feePlanTypeWithAmountList");
for (int k=0; k<feePlanTypeDetailsArray.length();k++){
FeeTermDetailsData feeTermDetailsData= new FeeTermDetailsData();
JSONObject feeTypeDetails= feePlanTypeDetailsArray.getJSONObject(k);
feeTermDetailsData.setFeeTypeName(feeTypeDetails.getString("feeTypeName"));
feeTermDetailsData.setFeeTypeAmount(feeTypeDetails.getInt("amount"));
feeTermDetailsDataList.add(feeTermDetailsData);
Log.i("feeTypeeee",feeTermDetailsDataList.toString());
}*/
JSONObject feePlanId = studentFeePlanObject.getJSONObject("feePlanId");
feeMonth.setFeePlanId(feePlanId.getInt("id"));
Log.i("monthhh", feeMonths.toString());
}
} catch (JSONException e) {
e.printStackTrace();
}
Log.i("finalDummyData", dummyfeeType.toString());
Log.i("finalFeeScheduleData", dummyfeeType.toString());
expandableAdapter = new ExpandableAdapter(Expandable.this, feeScheduleData, dummyfeeType);
layoutManager = new LinearLayoutManager(Expandable.this);
//expandableRecyclerview.setLayoutManager(layoutManager);
expandableRecyclerview.setAdapter(expandableAdapter);
/*expandableRecyclerview.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
Toast.makeText(Expandable.this, "doing well", Toast.LENGTH_SHORT).show();
expandableRecyclerview.getExpandableListAdapter();
/* expandableRecyclerview.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(Expandable.this, "its expanding", Toast.LENGTH_SHORT).show();
}
});
expandableRecyclerview.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(Expandable.this, "collapsing", Toast.LENGTH_SHORT).show();
}
});*/
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
mySingleton.getInstance(Expandable.this).addToRequestQueue(jsonObjectRequest);
}
}
MyAdapter类:
public class ExpandableAdapter extends BaseExpandableListAdapter {
Context context;
ExpandableAdapter expandableAdapter;
LayoutInflater inflater;
List<StudentFeeScheduleData> feeScheduleList = new ArrayList<StudentFeeScheduleData>();
ArrayList<ArrayList<FeeTermDetailsData>> feeTermDetailsDataList;
public ExpandableAdapter(Context context, List<StudentFeeScheduleData> feeScheduleList,
ArrayList<ArrayList<FeeTermDetailsData>> feeTermDetailsDataList) {
this.context = context;
this.feeScheduleList = feeScheduleList;
this.feeTermDetailsDataList = feeTermDetailsDataList;
}
@Override
public int getGroupCount() {
return feeScheduleList.size();
}
@Override
public int getChildrenCount(int groupPosition) {
System.out.println("lisss" + feeTermDetailsDataList.toString());
//return feeTermDetailsDataList.get(groupPosition).size();
return ((ArrayList<FeeTermDetailsData>) feeTermDetailsDataList.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return feeScheduleList.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return feeTermDetailsDataList.get(groupPosition).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.student_feeschedule_item, null);
}
StudentFeeScheduleData feeMonth = (StudentFeeScheduleData) getGroup(groupPosition);
/*ExpandableListView expandableListView= (ExpandableListView) parent;
expandableListView.expandGroup(groupPosition);*/
ViewHolder holder = new ViewHolder();
holder.feeSchedule = (TextView) convertView.findViewById(R.id.fee_schedule_item);
holder.dueAmount = (TextView) convertView.findViewById(R.id.total_termfee);
convertView.setTag(holder);
holder.feeSchedule.setText(feeMonth.getTerms());
String textAmount = String.valueOf(Double.valueOf(feeMonth.getTotalTermFee()));
holder.dueAmount.setText(textAmount);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
FeeTermDetailsData feeTermDetailsData = (FeeTermDetailsData) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fee_schedule_detailview, null);
}
ViewHolder holder = new ViewHolder();
holder.feeTypeName = (TextView) convertView.findViewById(R.id.fee_schedule_item);
holder.feeTypeAmount = (TextView) convertView.findViewById(R.id.total_termfee);
convertView.setTag(holder);
holder.feeTypeName.setText(feeTermDetailsData.getFeeTypeName());
String textAmount = String.valueOf(Double.valueOf(feeTermDetailsData.getFeeTypeAmount()));
holder.feeTypeAmount.setText(textAmount);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
static class ViewHolder {
TextView feeSchedule, dueAmount, feeTypeName, feeTypeAmount;
}
@Override
public void onGroupExpanded(int groupPosition) {
//getChild(0,groupPosition);
super.onGroupExpanded(groupPosition);
}
@Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
}
fee_schedule_detailview:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/fee_type_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/sampleDimension"
android:layout_weight="1"
android:text="Transportation"
android:textColor="@color/black"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/sampleDimension"
android:layout_weight="1"
android:text=":"
android:textColor="@color/black"
/>
<TextView
android:id="@+id/fee_type_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/sampleDimension"
android:layout_weight="1"
android:padding="@dimen/sampleDimension"
android:text="500"
android:textColor="@color/black"
/>
</LinearLayout>
</LinearLayout>
列表的Mylog:
04-26 12:05:53.690 28710-28710/com.example.sairam.dummy I/System.out:
lisss[FeeTermDetailsData{feeTypeName='TUTION FEE', feeTypeAmount=35160,
feeTypeId=573, feePlanScheduleId=219}, FeeTermDetailsData{feeTypeName='MESS
FEE', feeTypeAmount=0, feeTypeId=574, feePlanScheduleId=219},
FeeTermDetailsData{feeTypeName='TUTION FEE', feeTypeAmount=26370,
feeTypeId=575, feePlanScheduleId=220}, FeeTermDetailsData{feeTypeName='MESS
FEE', feeTypeAmount=0, feeTypeId=576, feePlanScheduleId=220},
FeeTermDetailsData{feeTypeName='TUTION FEE', feeTypeAmount=26370,
feeTypeId=577, feePlanScheduleId=221}, FeeTermDetailsData{feeTypeName='MESS
FEE', feeTypeAmount=0, feeTypeId=578, feePlanScheduleId=221}]
04-26 12:05:53.691 28710-28710/com.example.sairam.dummy I/System.out:
lisss[FeeTermDetailsData{feeTypeName='TUTION FEE', feeTypeAmount=35160,
feeTypeId=573, feePlanScheduleId=219}, FeeTermDetailsData{feeTypeName='MESS
FEE', feeTypeAmount=0, feeTypeId=574, feePlanScheduleId=219},
FeeTermDetailsData{feeTypeName='TUTION FEE', feeTypeAmount=26370,
feeTypeId=575, feePlanScheduleId=220}, FeeTermDetailsData{feeTypeName='MESS
FEE', feeTypeAmount=0, feeTypeId=576, feePlanScheduleId=220},
FeeTermDetailsData{feeTypeName='TUTION FEE', feeTypeAmount=26370,
feeTypeId=577, feePlanScheduleId=221}, FeeTermDetailsData{feeTypeName='MESS
FEE', feeTypeAmount=0, feeTypeId=578, feePlanScheduleId=221}]
在您的getChildView() method
,您错误地调用了getGroup(groupPosition)
,它不是FeeTermDetailsData的实例
更换
FeeTermDetailsData feeTermDetailsData = (FeeTermDetailsData) getGroup(groupPosition);
如
FeeTermDetailsData feeTermDetailsData = (FeeTermDetailsData) getChild(groupPosition,childPosition);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.