Androidアプリにて、ExpandableListViewを実装しようとしたのですが
エラーも吐かず、画面にViewが表示されないのでどこが間違っているか
ご指摘いただきたいです。
ListViewAdapterです。
public class ExpandableListViewAdapter extends BaseExpandableListAdapter { private final String TAG = this.getClass().getSimpleName(); private List<ExpandableListViewItem> children; private List<String> groups; private Context context; private LayoutInflater inflater; /** * Constructor */ public ExpandableListViewAdapter(Context ctx, List<String> groups, List<ExpandableListViewItem> children) { Log.d(TAG, "ExpandableListViewAdapter() start."); this.context = ctx; this.children = children; this.groups = groups; this.inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getGroupCount() { return 0; } @Override public int getChildrenCount(int groupPosition) { return 0; } @Override public Object getGroup(int groupPosition) { return groups.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return children.get(groupPosition); } @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) { Log.d(TAG, "getGroupView() start."); if(convertView == null){ convertView = inflater.inflate(R.layout.expandable_list_view_group, null); } TextView textView = (TextView) convertView.findViewById(R.id.expandable_group_text); textView.setText(this.groups.get(groupPosition)); // textView.setText((String) getGroup(groupPosition)); return convertView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { Log.d(TAG, "getChildView() start."); if(convertView == null){ convertView = inflater.inflate(R.layout.expandable_list_view_item, null); } final TextView textView = (TextView) convertView.findViewById( R.id.answer_text); // textView.setText(((ExpandableListViewItem) getChild(groupPosition, childPosition)).getText()); textView.setText(this.children.get(childPosition).getText()); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return false; } }
ExpandableListVIewを実装しようとしているActivityです。
public class ListViewActivity extends AppCompatActivity { private final String TAG = this.getClass().getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate() start."); super.onCreate(savedInstanceState); setContentView(R.layout.activity_faq); ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.faq_expandableListView); ExpandableListViewAdapter expandableListViewAdapter = new ExpandableListViewAdapter(this, createGroupItemList(), createChildrenItemList()); expandableListView.setAdapter(expandableListViewAdapter); } private List<ExpandableListViewItem> createChildrenItemList() { List<ExpandableListViewItem> result = new ArrayList<>(); result.add(new ExpandableListViewItem("ねこ1")); result.add(new ExpandableListViewItem("ねこ2")); result.add(new ExpandableListViewItem("コーギー1")); result.add(new ExpandableListViewItem("コーギー2")); return result; } private List<String> createGroupItemList() { List<String> groups = new ArrayList<>(); groups.add("test 01"); groups.add("test 02"); groups.add("test 03"); groups.add("test 04"); return groups; } }
ListItemのクラスです。
public class ExpandableListViewItem { private String text = ""; public ExpandableListViewItem(String text) { this.text = text; } public String getText() { return text; } public void setText(String text) { this.text = text; } }
IDのずれや、Viewのサイズの問題で表示されてないということは確認したのでないと思います。
自分として、ログにて
・"ExpandableListViewAdapter() start."は一度呼ばれている。
・"getChildView() start."は、一度も呼ばれていない。
・"getGroupView() start."は、一度も呼ばれていない。
がみられるので、なぜgetView系が呼ばれないのかが理解できていないです。
どなたかご教授いただけませんでしょうか。
宜しくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。