2016-07-22 6 views
0

グループテキストを表示することができましたが、子テキストを取得する方法がわからない場合は展開します。拡大リストビューで子オブジェクトが表示されない

List<TeamObject> listDataDoc; 
HashMap<TeamObject, List<DoctorObject>> listDataChildStaff; 

私のアダプタにlistDataDocとListDataChildStaffを渡しています。私の主な活動では:

listAdapter = new ExpandableListAdapter(this, listDataDoc, listDataChildStaff); 

これまで私はprepareListData()を呼び出しています。

private void prepareListData() { 
    listDataDoc = new ArrayList<>(); 
    listDataChildStaff = new HashMap<>(); 

    ArrayList<TeamObject> all = new ArrayList<>(); 


    TeamObject adil = new TeamObject(); 
    adil.setStaffName("Adil Patel"); 
    adil.setStaffType(1); 

    listDataDoc.add(adil); 

    List<DoctorObject> adilGroup = new ArrayList<>(); 

    DoctorObject cindy = new DoctorObject("Cindy G"); 

    DoctorObject Bettina = new DoctorObject("Bettina"); 

    adilGroup.add(cindy); 
    adilGroup.add(Bettina); 

    listDataChildStaff.put(listDataDoc.get(0),adilGroup); 

マイアダプタはその後、次のようになります。

enter image description here

グレート:私はそのコードでアプリケーションを実行すると、私が最初にこれを取得

public class ExpandableListAdapter extends BaseExpandableListAdapter { 

private Context _context; 
private List<TeamObject> _listDataHeader; // header titles 
private HashMap<TeamObject, List<DoctorObject>> _listDataChild; 

//Keep track of checks 
//ArrayList<ArrayList<Integer>> check_states = new ArrayList<ArrayList<Integer>>(); 

public ExpandableListAdapter(Context context, List<TeamObject> listDataHeader, HashMap<TeamObject, List<DoctorObject>> 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_create_team_child, null); 
    } 

    final CheckBox chk = (CheckBox) convertView.findViewById(R.id.checkBoxChild); 

    chk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 

             @Override 
             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
               if (isChecked == true){ 
                //_listDataChild.get(childPosition) 
               } 
             } 
            } 
    ); 

    //String test = String.valueOf(_listDataChild.containsKey("Adil")); 

    TextView txtListChild = (TextView) convertView 
      .findViewById(R.id.teamNameChild); 

    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) { 



    if (convertView == null) { 
     LayoutInflater infalInflater = (LayoutInflater) this._context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = infalInflater.inflate(R.layout.list_item_create_team, null); 
    } 

    TextView lblListHeader = (TextView) convertView 
      .findViewById(R.id.teamName); 
    lblListHeader.setTypeface(null, Typeface.BOLD); 
    lblListHeader.setText(_listDataHeader.get(groupPosition).getStaffName()); 

    return convertView; 
} 

@Override 
public boolean hasStableIds() { 
    return false; 
} 

@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    return true; 
} 

}

!私はライン54次のエラー

FATAL EXCEPTION: main 
                    Process: com.adilpatel.vitalengine, PID: 4493 
                    java.lang.ClassCastException: com.adilpatel.vitalengine.expand.DoctorObject cannot be cast to java.lang.String 
                     at com.adilpatel.vitalengine.Expand2.ExpandableListAdapter.getChildView(ExpandableListAdapter.java:54) 

を取得

を展開したときしかし:

final String childText = (String) getChild(groupPosition, childPosition); 

私は、これは間違っている知っているが、私の子オブジェクトから名前を取得する方法イムわかりません。

+0

DoctorObjectはどのようなものです\ –

+0

@RobinDijkhof DoctorObjectは、名前、専門性と少数を持つオブジェクトです:代わりにあなたのDoctorObject(これgetStringリターン名またはDoctroObjectのタイトル)でgetString()メソッドを作成し、次の操作を行い、これを行うのより多くの事。基本的にはどのように指定するのですか.getName(); – Adilp

答えて

1

DoctorObjectをStringにキャストしたいと思っています。それはできません。

DoctorObject model = (DoctorObject)getChild(groupPosition, childPosition); 
String childText = model.getName(); 
+0

私はこれをやって、ラベルを表示したときに "com .... DoctorObject @ 2c36 ...."と表示されるようになりました。それ以降は同じですが "@ 3fd ..."これはオブジェクトの参照を文字列として表示すると仮定していますか?また、DoctorObjectには、名前、専門分野、場所などの属性がいくつかあります。どうにかして.getName();でなければなりません。どこかに。 – Adilp

+0

@Adilpええ、それは文字列を返します。 getString()は戻り値の名前または場所を意味します。 – Amir

+0

私はmetionを忘れてしまった.getString();動作しません。私はtoString()を使用しなければならなかった。何かが現れるようにする。同じ方法で.getName();動作しません。唯一のオプションはtoString、equals、hashCodeなどでした。 – Adilp

関連する問題