ExpandableListView
은 서버 측 (reftrofit)에서 오는 데이터를 사용하여 채워지는데 어떻게 Adapter
을 사용할 수 있습니까? 객체의 특정 요소를 가져 오겠습니까? 확장 가능한 목록보기에는 상위 및 하위 요소가 포함됩니다. 자식 요소를 클릭하면 해당 자식 요소와 연결된 ID (SensorID)를 추출하고 싶습니다.서버 측에서 오는 데이터를 사용하여 목록보기를 채우는 경우 어댑터의 특정 요소를 가져 오는 방법
나는 개체에서 ID를 추출하려고하는데 Adapter
이 있는데 그럴 수 없습니다. 배열 Adapter
에 대해 getItemAtPosition()
메서드를 사용하여 인덱스를 얻은 다음 객체 (sensorID)에서 요소를 추출하는 것으로 나타났습니다. 그러나이 방법은 ExpandableListAdapter
에 사용해야하는 동일한 방법인지 확실하지 않습니다. 왜냐하면 getChild()
메서드를 사용하는 코드 스 니펫을 보았 기 때문입니다.
내가 클릭 할 때마다 얻을 오류는 ExpandableListConnector가 에 com.xera.deviceinsight.home.ExpandableListAdapter
문제의 방법을 캐스트 할 수없는
읽고
private void load(View view) { expListView = (ExpandableListView) view.findViewById(R.id.lvExp); prepareListData(); listAdapter = new ExpandableListAdapter(this.getActivity(), listDataHeader, listDataChild); expListView.setAdapter(listAdapter); expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { System.err.println("child clicked"); Toast.makeText(getActivity(), "child clicked", Toast.LENGTH_SHORT).show(); EventBus.getDefault().post(new ItemClickedEvent(SensorInformationChildFragment.TAB_CALL)); ExpandableListAdapter adapter = (ExpandableListAdapter)parent.getAdapter(); OrganisationDeviceSensorsResult deviceSensor = (OrganisationDeviceSensorsResult) adapter.getChild(groupPosition , childPosition); sensorID = deviceSensor.SensorID; ReportingGroup.get(childPosition); return true; } }); }
어댑터 :
public class ExpandableListAdapter extends BaseExpandableListAdapter { private Context _context; private List<String> _listDataHeader; // header titles // child data in format of header title, child title private HashMap<String, List<String>> _listDataChild; public List<OrganisationDeviceSensorsResult> Items; 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; } public OrganisationDeviceSensorsResult getItemAtPosition(int index) { return getItemAtPosition(index); //return this.getItem(index); //return this.getItem(index); //return index; //return this.get //return OrganisationDeviceSensorsResult. } @Override public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { final String childText = (String) getChild(groupPosition, childPosition); OrganisationDeviceSensorsResult deviceSensor = getItemAtPosition(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.lblListHeader); 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; } }
안녕하세요. 귀하의 경우에는 chatgroupList가 무엇입니까? 대신이 활동을 참조하는 코드 줄이 있습니다. 'ListAdapter = new ExpandableListAdapter (this.getActivity(), listDataHeader, listDataChild); ' – Zidane
@Zidane 지연되었습니다. 내 chatGroupList는 어댑터에 제공하는 목록으로, 표시 할 개체가 들어 있습니다. 귀하의 경우, 당신은 2 ist, listDataHeader 및 listDataChild – Shudy
그 getContacts 메서드가 나를 혼란스럽게하는 유일한 방법은 다른 모든 게 의미가 – Zidane