같은 주제의 링크를 방문했지만 em 중 아무 것도 내 질문에 대답하지 않았습니다. 간단하게 확장 가능한 목록보기를 사용하여 사용자 지정 확장 가능 목록보기를 만들고 싶지 않습니다. 성공적으로 mysql 데이터베이스에서 데이터를 가져올 수 있고 토스트 메시지를 사용하여 검색되는 모든 값을 확인하고 또한 우편 배달부를 사용하여 PHP 스크립트를 테스트했습니다.
이제 가져온 값을 ExpandableListView에 표시하려고합니다.
이것은 내가 데이터베이스에서 값을 가져 오는 함수를 사용하고 내가 값을 얻고,하지만 난 ExpandableListView에서 그 값을 인쇄 할 수 없습니다입니다
mysql에서 데이터 가져 오기 androidable의 ExpandableListView에 데이터 표시
<?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="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/lblListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"/>
</LinearLayout>
list_child.xml 파일입니다. 이 기능은 내가 먼저 이름, 이메일과 위의 기능 이드 리턴 같은 아이 뷰를 얻고 확장 가능한 목록보기에서 확장 목록보기
private void ListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String,List<String>>();
//Adding header to expandable list view
listDataHeader.add("ABC");
listDataHeader.add("DEF");
//Adding child data
List<String> abc = new ArrayList<>();
abc.add(fetchAbc());
List<String> def = new ArrayList<>();
def.add(fetchDef());
//Header child data
listDataChild.put(listDataHeader.get(0),abc);
listDataChild.put(listDataHeader.get(1),def);
}
private String fetchAbc() {
return ("first name : \t"+Name+"\nEmail : \t"+email);
}
private String fetchDef() {
return ("Id : \t"+id);
}
을 준비합니다. 그러나 가치는 아닙니다. 확장형 광고 어댑터 클래스 파일
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader;
private HashMap<String,List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.header);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
고맙습니다.
가능한 복제 (http://stackoverflow.com/questions/17523257/expandable-listview-with-dynamic-data-in-android)는 I –
링크 체크 또한 대답은 OP가 답변을 수락하지 않았 음을 알아야합니다. 그리고 커스텀 익스텐더 블리스트 뷰를 생성하고 싶지는 않습니다. –