我的应用程序中有一个可扩展的列表视图,即子组从sqlite数据库插入。 并且我的应用中不会更改组标题。
群组显示在列表中,但孩子们没有显示。
这是我的适配器:
package ir.TeenStudio.ActivitiesManagement;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
public class ActivitiesExpandableListAdapter extends BaseExpandableListAdapter {
Activity activity;
ArrayList<String> groupsList;
HashMap<Integer, ArrayList<HashMap<String,String>>> childsList;
private ArrayList<HashMap<String,String>> items;
private HashMap<String, String> item;
private String groupItem;
ActivitiesExpandableListAdapter(Activity activity, ArrayList<String> groupsList, HashMap<Integer, ArrayList<HashMap<String,String>>> childsList) {
this.activity = activity;
this.groupsList = groupsList;
this.childsList = childsList;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this.childsList.get(this.groupsList.get(groupPosition)).get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosititon) {
return childPosititon;
}
@Override
public View getChildView(int groupPosition, int childPosititon, boolean isLastChild, View convertView,
ViewGroup parent) {
View v = convertView;
Holder viewHolder;
if (v==null) {
v = this.activity.getLayoutInflater().inflate(R.layout.list_item, null);
viewHolder = new Holder();
Typeface Rezvan = Typeface.createFromAsset(activity.getAssets(), "fonts/rezvan.ttf");
viewHolder.ChildDescription = (TextView) v.findViewById(R.id.itemDescription);
viewHolder.ChildLocation = (TextView) v.findViewById(R.id.itemLocation);
viewHolder.ChildTime = (TextView) v.findViewById(R.id.itemTime);
viewHolder.ChildDate = (TextView) v.findViewById(R.id.itemDate);
viewHolder.ChildAlarmTime = (TextView) v.findViewById(R.id.alarmTime);
viewHolder.ChildAlarmText = (TextView) v.findViewById(R.id.alarmText);
viewHolder.ChildTime.setTypeface(Rezvan);
viewHolder.ChildAlarmTime.setTypeface(Rezvan);
viewHolder.ChildDate.setTypeface(Rezvan);
v.setTag(viewHolder);
}
else
viewHolder = (Holder)v.getTag();
this.items = this.childsList.get(groupPosition);
this.item = this.items.get(childPosititon);
viewHolder.ChildDescription.setText(this.item.get("Description"));
if (Integer.parseInt(this.item.get("AddLocation"))==1) {
viewHolder.ChildLocation.setText(this.item.get("Location"));
} else ((LinearLayout)v.findViewById(R.id.location)).setVisibility(View.GONE);
if (Integer.parseInt(this.item.get("AddHour"))==1) {
viewHolder.ChildTime.setText(this.item.get("Hour")+":"+this.item.get("Minutes"));
} else viewHolder.ChildTime.setVisibility(View.GONE);
if (Integer.parseInt(this.item.get("AddDate"))==1) {
viewHolder.ChildDate.setText(this.item.get("DateYear")+"/"+this.item.get("DateMonth")+"/"+this.item.get("DateDay"));
} else ((LinearLayout)v.findViewById(R.id.date)).setVisibility(View.GONE);
if (Integer.parseInt(this.item.get("AddAlarm"))==1) {
if (Integer.parseInt(this.item.get("AlarmTime"))==0) {
viewHolder.ChildAlarmTime.setText("");
viewHolder.ChildAlarmText.setText("در زمان مشخص شده");
} else {
viewHolder.ChildAlarmTime.setText(this.item.get("AlarmTime"));
viewHolder.ChildAlarmText.setText("دقیقه بعد از زمان مشخص شده");
}
} else ((LinearLayout)v.findViewById(R.id.alarm)).setVisibility(View.GONE);
notifyDataSetChanged();
return v;
}
@Override
public int getChildrenCount(int groupPosition) {
return 0;
}
@Override
public Object getGroup(int groupPosition) {
return this.groupsList.get(groupPosition);
}
@Override
public int getGroupCount() {
return this.groupsList.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView;
Holder viewHolder;
if (v == null) {
v = this.activity.getLayoutInflater().inflate(R.layout.listview_group, null);
viewHolder = new Holder();
viewHolder.GroupTitle = (TextView) v.findViewById(R.id.itemDes);
Typeface Naskh = Typeface.createFromAsset(activity.getAssets(), "fonts/droid_naskh.ttf");
viewHolder.GroupTitle.setTypeface(Naskh);
v.setTag(viewHolder);
} else viewHolder = (Holder)v.getTag();
this.groupItem = this.groupsList.get(groupPosition);
viewHolder.GroupTitle.setText(this.groupItem);
return v;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
private class Holder {
public TextView ChildDescription;
public TextView ChildLocation;
public TextView ChildTime;
public TextView ChildDate;
public TextView ChildAlarmTime;
public TextView ChildAlarmText;
public TextView GroupTitle;
}
}
我不知道为什么但是当我开始app孩子不显示。 我知道适配器的主要活动的输入值是正确的。
答案 0 :(得分:0)
更改此
@Override
public int getChildrenCount(int groupPosition) {
return 0;
}
到此:
@Override
public int getChildrenCount(int groupPosition) {
return this.childsList.get(groupPosition)
.size();
}
你返回了childCount,零,所以你可以看到群组,但没有孩子。