我已记录group position
和child position
的值
但即使我点击不同的项目,它也会在日志中显示相同的childposition
。
我为不同的group Position
获得了不同的价值,但child position
的价值却不同。
我想将所选的子位置传递给下一个活动,以便我可以调用api并存储该特定位置的值。
Here is the image of what i wanna do.
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
private HashMap<String, List<String>> _listDataChild;
private LinearLayout timming, services, managediscount, editlocation;
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,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);
}
Log.i("child","child position" + String.valueOf(childPosition));
Log.i("child","parent position" + String.valueOf(groupPosition));
this.timming = convertView.findViewById(R.id.timming);
this.services = convertView.findViewById(R.id.services);
this.managediscount = convertView.findViewById(R.id.managediscount);
this.editlocation = convertView.findViewById(R.id.editlocation);
timming.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openTimmingEditActivity(_context);
}
});
services.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openServicesRatesEditActivity(_context);
}
});
managediscount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openManageDiscountEditActivity(_context);
}
});
// 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 = convertView.findViewById(R.id.lblListHeader);
if (isExpanded) {
convertView.findViewById(R.id.expand).setVisibility(View.GONE);
convertView.findViewById(R.id.collapse).setVisibility(View.VISIBLE);
convertView.findViewById(R.id.listGroupLayout).setBackgroundResource(R.drawable.login_border);
lblListHeader.setTextColor(Color.parseColor("#ffffff"));
convertView.findViewById(R.id.viewSpace).setVisibility(View.GONE);
} else {
convertView.findViewById(R.id.expand).setVisibility(View.VISIBLE);
convertView.findViewById(R.id.collapse).setVisibility(View.GONE);
convertView.findViewById(R.id.listGroupLayout).setBackgroundColor(Color.parseColor("#BFBFBF"));
lblListHeader.setTextColor(Color.parseColor("#757575"));
convertView.findViewById(R.id.viewSpace).setVisibility(View.INVISIBLE);
}
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;
}
public void openTimmingEditActivity(Context context) {
Intent myactivity = new Intent(context.getApplicationContext(), TimmingEditActivity.class);
myactivity.addFlags(FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(myactivity);
}
public void openServicesRatesEditActivity(Context context) {
Intent myactivity = new Intent(context.getApplicationContext(), ServicesRatesEditActivity.class);
myactivity.addFlags(FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(myactivity);
}
public void openManageDiscountEditActivity(Context context) {
Intent myactivity = new Intent(context.getApplicationContext(), ManageDiscountEditActivity.class);
myactivity.addFlags(FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(myactivity);
}
记录:
06-15 17:17:31.065 10265-10265/com.janelaaj I/child: child position0
06-15 17:17:31.065 10265-10265/com.janelaaj I/child: parent position2
06-15 17:17:40.485 10265-10265/com.janelaaj I/child: child position0
06-15 17:17:40.485 10265-10265/com.janelaaj I/child: parent position1
06-15 17:17:56.928 10265-10265/com.janelaaj I/child: child position0
06-15 17:17:56.928 10265-10265/com.janelaaj I/child: parent position0
06-15 17:17:58.904 10265-10265/com.janelaaj I/child: child position0
06-15 17:17:58.904 10265-10265/com.janelaaj I/child: parent position1
06-15 17:17:58.966 10265-10265/com.janelaaj I/child: child position0
06-15 17:17:58.966 10265-10265/com.janelaaj I/child: parent position2