我已经创建了自定义展开式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);
}
// } }
}
// }
});