2017-03-16 2 views
0

실패하고 내포 한 "어댑터"와 조각을 호출하는 ExpandableListView 객체가있는 이유는 무엇인지 이해할 수 없기 때문에 특정 프로그램에 대해 조금 의심스러워합니다. 이 객체. 목록의 요소를 표시 할 때 문제는 onChildClick에 있습니다. 목록에서 항목을 누르면 TextView에 저장되고 나중에 사용하도록 표시됩니다. 이 프로그램은 지금 내 프로그램이므로 다른 요소를 치면 눌렀을 때 목록의 첫 번째 요소 만 선택됩니다. 응용 프로그램이 오류없이 작업을 중단합니다. 이 문제를 해결하려면 어떻게해야합니까? 고맙습니다. 어떻게 요소를 setOnChildClickListener와 함께 표시 할 수 있습니까?

내가
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.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; 
    } 
} 

getChild

호출하는 ExpandibleList의 대상이되고 나는 목록에서 항목을 얻고 싶은 곳이다.

public class MainActivityFragment extends Fragment { 

//Expandable list Adapter 
    ExpandableListAdapter listAdapter; 
    ExpandableListView expListView; 
    List<String> listDataHeader; 
    HashMap<String, List<String>> listDataChild; 

    //Users 
    private List <User> items = new ArrayList<>(); 

    //Obejeto a pasar 
    User user = new User(); 
    String password; 

@Override 
    public View onCreateView(LayoutInflater inflater, final ViewGroup container, 
          Bundle savedInstanceState) { 
     view = inflater.inflate(R.layout.fragment_main, container, false); 

     //Botones 
     TextPass = (EditText) view.findViewById(R.id.IdpasswordUser); 
     TextName = (TextView) view.findViewById(R.id.text1); 

     // get the listview 
     expListView = (ExpandableListView) view.findViewById(R.id.lvExp); 

     // preparing list data 
     prepareListData(); 

     listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild); 

     // setting list adapter 
     expListView.setAdapter(listAdapter); 

     ExpandableListView ExList =(ExpandableListView) view.findViewById(R.id.lvExp) ; 



       //Llamamos al boton fichar 
     fichar = (Button) view.findViewById(R.id.fichar); 

//Call ExpandibleList view child on pressed 

     ExList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 

      @Override 
      public boolean onChildClick(ExpandableListView parent, View v, 
             int groupPosition, int childPosition, long id) { 

       ShowItem(listDataHeader.get(childPosition)); 

       TextName.setText(listAdapter.getChild(groupPosition,childPosition).toString()); 

       return false; 
      } 
     }); 

     fichar.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       password = TextPass.getText().toString(); 
       //SuperUsuario 
       if(key.equalsIgnoreCase("cesi.tic")&&password.equalsIgnoreCase("123456789")){ 
        ((MainActivity) getActivity()).EditarUsuario(); 
        fichar.setVisibility(view.INVISIBLE); 
        TextPass.setVisibility(view.INVISIBLE); 
        TextDNI.setVisibility(view.INVISIBLE); 
       }else{ 
        LeerFirebase(); 
       } 

      } 
     }); 
     return view; 
    } 
    public void ShowItem(String id) 
    { 
     // do something 
    } 
} 

가 어떻게

답변

0

좋아 setOnChildClickListener 표시 요소를 얻을 수있다, 난 이미 문제를 해결했습니다. 방금 을 제거해야합니다. // ShowItem (listDataHeader.get (childPosition));

그래서 onChildClick은 다음과 같이 보일 것이다 :

expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 

      @Override 
      public boolean onChildClick(ExpandableListView parent, View v, 
             int groupPosition, int childPosition, long id) { 

       TextName.setText(listAdapter.getChild(groupPosition,childPosition).toString()); 

       return false; 
      } 
     }); 
관련 문제