1 / 1 / 0
Регистрация: 28.06.2017
Сообщений: 49
|
|
1
|
ExpandableListView адаптер некорректно работает
17.09.2017, 20:08. Показов 717. Ответов 1
Здравствуйте, помогите найти ошибку. Адаптер не распределяет объекты по своим группам, передает все в 1-ю группу.
ListAdapter
Кликните здесь для просмотра всего текста
Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
| package com.example.eminem.expandablelistview2;
/**
* Created by eminem on 17.09.2017.
*/
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import java.util.HashMap;
import java.util.List;
public class ListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<groupTitle> expListTitle;
public ListAdapter(Context context, List<groupTitle> expListTitle) {
this.context = context;
this.expListTitle = expListTitle;
}
@Override
public Object getChild(int listPosition, int expListPosition) {
return expListTitle.get(listPosition).getCheilds().get(expListPosition);
}
@Override
public long getChildId(int listPosition, int expandedListPosition) {
return expandedListPosition;
}
@Override
public View getChildView(int listPosition, final int expandedListPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// получаем дочерний элемент
Cheild expListText = (Cheild) getChild(listPosition, expandedListPosition);
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.list_item, null);
}
// TextView expListTextView = (TextView) convertView.findViewById(R.id.expandedListItem);
// expListTextView.setText(expListText.getTitle());
//
// TextView info = (TextView) convertView.findViewById(R.id.infoCh);
// info.setText(expListText.getInfo());
//
// TextView status = (TextView) convertView.findViewById(R.id.satus);
// status.setText(expListText.getStatus());
//
// ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView2);
// imageView.setImageResource(expListText.getIdImg());
return convertView;
}
@Override
public int getChildrenCount(int listPosition) {
return expListTitle.get(listPosition).getCheilds().size();
}
@Override
public Object getGroup(int listPosition) {
return expListTitle.get(listPosition);
}
@Override
public int getGroupCount() {
return expListTitle.size();
}
@Override
public long getGroupId(int listPosition) {
return listPosition;
}
@Override
public View getGroupView(int listPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// получаем родительский элемент
groupTitle listTitle = (groupTitle) getGroup(listPosition);
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.list_group, null);
}
TextView listTitleTextView = (TextView) convertView.findViewById(R.id.listTitle);
listTitleTextView.setText(listTitle.getTitle());
TextView hint = (TextView) convertView.findViewById(R.id.hint);
hint.setText(listTitle.getHint());
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageViewGroup);
imageView.setImageResource(listTitle.getIdImg());
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int listPosition, int expandedListPosition) {
return true;
}
} |
|
ListData
Кликните здесь для просмотра всего текста
Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| package com.example.eminem.expandablelistview2;
/**
* Created by eminem on 17.09.2017.
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ListData {
public static List<groupTitle> loadData()
{
List<groupTitle> expDetails = new ArrayList<>();
List<Cheild> oopLanguages = new ArrayList<>();
oopLanguages.add(new Cheild("Java", "info1", "5", R.drawable.buses_yellow));
groupTitle groupTitle1 = new groupTitle("Ушедшие", "уже ушли", R.drawable.buses_yellow, oopLanguages);
List<Cheild> structuredLanguages = new ArrayList<>();
oopLanguages.add(new Cheild("Pascal", "info2", "3", R.drawable.buses_yellow));
groupTitle groupTitle2 = new groupTitle("В пути", "уже едет", R.drawable.buses_yellow, structuredLanguages);
List<Cheild> functionalLanguages = new ArrayList<>();
oopLanguages.add(new Cheild("C#", "info3", "4", R.drawable.buses_yellow));
groupTitle groupTitle3 = new groupTitle("Ближайшие", "будут ехать", R.drawable.buses_yellow, functionalLanguages);
expDetails.add(groupTitle1);
expDetails.add(groupTitle2);
expDetails.add(groupTitle3);
return expDetails;
}
} |
|
groupTitle
Кликните здесь для просмотра всего текста
Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
| package com.example.eminem.expandablelistview2;
import java.util.List;
/**
* Created by eminem on 17.09.2017.
*/
public class groupTitle {
private String title;
private String hint;
private Integer idImg;
private List<Cheild> cheilds;
public groupTitle(String title, String hint, Integer idImg, List<Cheild> cheilds) {
this.title = title;
this.hint = hint;
this.idImg = idImg;
this.cheilds = cheilds;
}
public groupTitle() {
}
public List<Cheild> getCheilds() {
return cheilds;
}
public void setCheilds(List<Cheild> cheilds) {
this.cheilds = cheilds;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getHint() {
return hint;
}
public void setHint(String hint) {
this.hint = hint;
}
public Integer getIdImg() {
return idImg;
}
public void setIdImg(Integer idImg) {
this.idImg = idImg;
}
} |
|
0
|