如何根据Imageview获取子位置点击Expandable Listview

时间:2017-09-28 12:02:30

标签: android media-player expandablelistview expandablelistadapter

我已经创建了自定义展开式ListView,因为我希望点击ImageView时的子位置,因为我的子视图包含ImageView,并且点击图片时我想要其特定的子位置和小组位置。在我的自定义展开式ListView childview中有音频文件,即ImageView按钮播放和暂停,以获取我已setTag()getTag()的位置,但我仍然是我无法得到: 这是下面的可扩展适配器

 @Override
 public View getChildView(int groupPosition, int childPosition,
        final 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);
    imgChild = (ImageView) convertView
            .findViewById(R.id.addunavailgreet);
    /*String pos=  _listDataChild.get(_listDataHeader.get(groupPosition)).get(
            childPosition);
     long child=getChildId( groupPosition,  childPosition);*/

    // imgChild.setTag((int)child);
    imgChild.setTag(groupPosition + childPosition);

    imgChild.setOnClickListener(this);

    txtListChild.setText(childText);
    return convertView;
}

我为ImageView创建了一个界面,点击它的片段类

    public interface OnItemClickListener {

    public void onAudioClick(View v, ImageView i,int childposition) throws Exception;
} 

其onclick:

  @Override
public void onClick(View v) {
    if (listener != null) {

        if(v.getId()== R.id.addunavailgreet){
            try {
                int child_position = (Integer)v.getTag();

                listener.onAudioClick(v, imgChild,child_position);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }

}

可扩展的ListView片段类,它在片段

中调用覆盖onAudioclick()
listAdapter.SetOnItemClickListener ( 
    new ExpandableListAdapter.OnItemClickListener() {

    @Override
    public void onAudioClick
    (View v, ImageView i ,int childposition) throws Exception {
        Cursor cursor;
        int child_position = (Integer) v.getTag();

        if (listAdapter.getGroup(group_position).equals("Unavailable Greeting")) {
            long post = listAdapter.getChildId((int) pos, child_position);
            System.out.println("Unavailable groupPosition" + group_position + child_position);
        }
        if (listAdapter.getGroup(group_position).equals("Name Greeting")) {
            long post = listAdapter.getChildId((int) pos, child_position);
            System.out.println("Name groupPosition" + group_position + child_position);
        }
        // if(listAdapter.getGroup(child_position).equals("Unavailable Greeting")) {
        if (childposition == 0) {
            /*String child =listDataChild.get(listDataHeader.get((int)pos)).get(
                    childposition);*/
            String child = (String) listAdapter.getChild(group_position, child_position);

            //Do what even you like in for the clicked group
            int position = (Integer) v.getTag();
            String file_name = listDataChild.get(position).toString();
            //  String file_full_path = dbpath + file_name;

            // path = getPathFromURI(getActivity(), uri);
            System.out.println("sourcepath" + path);
            path = getPathFromURI(getActivity(), uri);
            //String child =  (String) listAdapter.getChild((int)pos, child_position);
            String pathfile = new File(child).getName();
            //System.out.println("ChildPath" + pathfile);
            //String file_name = (String) listAdapter.getChild((int)pos, (int)childpos) ;
            initMediaPlayer(child, getActivity(), i, v, child_position);
        }
        //  }
        //  if(listAdapter.getGroup(child_position).equals("Name Greeting")) {
        if (childposition == 1) {
            /*String child =listDataChild.get(listDataHeader.get((int)pos)).get(
                        childposition);*/
            String child = (String) listAdapter.getChild((int) pos, child_position);
            pos = listAdapter.getGroupId(child_position);
            childpos = listAdapter.getChildId((int) pos, childposition);
            int position = (Integer) v.getTag();
            String file_name = String.valueOf(position);
            //   String file_full_path = dbpath + file_name;
            //Do what even you like in for the clicked group

            // path = getPathFromURI(getActivity(), uri);
            System.out.println("sourcepath1" + path);
            //  String child =  (String) listAdapter.getChild((int)pos, child_position);
            String pathfile = new File(child).getName();
            //System.out.println("ChildPath" + pathfile);
            //String file_name =  (String) listAdapter.getChild((int)pos, (int)childpos) ;
            initMediaPlayer(child, getActivity(), i, v, child_position);
        }

        // } }
    }

    // }
});

0 个答案:

没有答案