Java 可扩展列表视图未显示child
我的应用程序中有一个可扩展的listview,可以从sqlite数据库中插入组childs。 在我的应用程序中,组标题不会更改 组显示在列表中,但未显示childs 这是我的适配器:Java 可扩展列表视图未显示child,java,android,Java,Android,我的应用程序中有一个可扩展的listview,可以从sqlite数据库中插入组childs。 在我的应用程序中,组标题不会更改 组显示在列表中,但未显示childs 这是我的适配器: package ir.TeenStudio.ActivitiesManagement; import java.util.ArrayList; import java.util.HashMap; import android.app.Activity; import android.content.Co
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;
}
}
我不知道为什么,但当我启动应用程序时,孩子们不会出现。
我确认来自适配器主活动的输入值是正确的。更改此设置
@Override
public int getChildrenCount(int groupPosition) {
return 0;
}
为此:
@Override
public int getChildrenCount(int groupPosition) {
return this.childsList.get(groupPosition)
.size();
}
您返回了childCount,零,这样您可以看到组,但没有子组。您将childCount设置为零检查下面的答案当我尝试此操作时,我得到了force closejava.lang.NullPointerExceptionchange answer,使用该选项我尝试了这段代码,但我在getChildrenCount获得了强制关闭java.lang.NullPointerException:help Me您获得了NullPointerException,因为childsList或groupsList为null。检查您是否将它们的值传递给它们