使用可扩展列表视图和基本可扩展列表适配器时,Android截击请求不起作用
不知道为什么我的截击请求没有显示任何东西。如果我使用带BaseExpandableListAdapter的ExpandableListView,它不会给我失败实例,但success listner不会调用使用可扩展列表视图和基本可扩展列表适配器时,Android截击请求不起作用,android,expandablelistview,android-volley,Android,Expandablelistview,Android Volley,不知道为什么我的截击请求没有显示任何东西。如果我使用带BaseExpandableListAdapter的ExpandableListView,它不会给我失败实例,但success listner不会调用 public class ShopCategoryExpandibleListAdapter extends BaseExpandableListAdapter { final String _appLogTag = " - ShopCategoryExpandibleListAdapt
public class ShopCategoryExpandibleListAdapter extends BaseExpandableListAdapter {
final String _appLogTag = " - ShopCategoryExpandibleListAdapter - ";
// Define activity context
private Context mContext;
/*
* Here we have a Hashmap containing a String key
* (can be Integer or other type but I was testing
* with contacts so I used contact name as the key)
*/
private Map<ShopCategorySectionVO, List<ShopCategory>> mListDataChild;
// ArrayList that is what each key in the above
// hashmap points to
private List<ShopCategorySectionVO> mCategorySectionVOs;
// Hashmap for keeping track of our checkbox check states
private Map<Integer, boolean[]> mChildCheckStates;
// Our getChildView & getGroupView use the viewholder patter
// Here are the viewholders defined, the inner classes are
// at the bottom
private ChildViewHolder childViewHolder;
private GroupViewHolder groupViewHolder;
/*
* For the purpose of this document, I'm only using a single
* textview in the group (parent) and child, but you're limited only
* by your XML view for each group item :)
*/
private String groupText;
private String childText;
//private String childText2;
/* Here's the constructor we'll use to pass in our calling
* activity's context, group items, and child items
*/
public ShopCategoryExpandibleListAdapter(Context context,
List<ShopCategorySectionVO> listDataGroup,
Map<ShopCategorySectionVO, List<ShopCategory>> listDataChild) {
Log.d(_appLogTag, "Inside Constructor");
mContext = context;
mCategorySectionVOs = listDataGroup;
mListDataChild = listDataChild;
// Initialize our hashmap containing our check states here
mChildCheckStates = new HashMap<Integer, boolean[]>();
}
@Override
public ShopCategory getChild(int groupPosition, int childPosition) {
Log.d(_appLogTag, "Inside getChild");
List<ShopCategory>
listOfChilds = mListDataChild.get(mCategorySectionVOs.get(groupPosition));
Log.d(_appLogTag, "So total number of childs in Group number "
+groupPosition+" are "+listOfChilds.size());
//return mListDataChild.get(mCategorySectionVOs.get(groupPosition)).get(childPosition);
return listOfChilds.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
Log.d(_appLogTag, "Inside getChild ID");
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
Log.d(_appLogTag, "Inside getChild View");
final int mGroupPosition = groupPosition;
final int mChildPosition = childPosition;
// I passed a text string into an activity holding a getter/setter
// which I passed in through "ExpListChildItems".
// Here is where I call the getter to get that text
//childText = getChild(mGroupPosition, mChildPosition).getChildText();
ShopCategory shopCategory = getChild(mGroupPosition, mChildPosition);
childText = shopCategory.getTitle().getEn();
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_item, null);
childViewHolder = new ChildViewHolder();
childViewHolder.mChildText = (TextView) convertView.findViewById(R.id.laptop_child);
childViewHolder.mCheckBox = (CheckBox) convertView
.findViewById(R.id.checkBox);
convertView.setTag(R.layout.child_item, childViewHolder);
} else {
childViewHolder = (ChildViewHolder) convertView
.getTag(R.layout.child_item);
}
childViewHolder.mChildText.setText(childText);
//childViewHolder.mChildText2.setText(childText2);
/*
* You have to set the onCheckChangedListener to null
* before restoring check states because each call to
* "setChecked" is accompanied by a call to the
* onCheckChangedListener
*/
childViewHolder.mCheckBox.setOnCheckedChangeListener(null);
if (mChildCheckStates.containsKey(mGroupPosition)) {
/*
* if the hashmap mChildCheckStates<Integer, Boolean[]> contains
* the value of the parent view (group) of this child (aka, the key),
* then retrive the boolean array getChecked[]
*/
boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
// set the check state of this position's checkbox based on the
// boolean value of getChecked[position]
childViewHolder.mCheckBox.setChecked(getChecked[mChildPosition]);
} else {
/*
* if the hashmap mChildCheckStates<Integer, Boolean[]> does not
* contain the value of the parent view (group) of this child (aka, the key),
* (aka, the key), then initialize getChecked[] as a new boolean array
* and set it's size to the total number of children associated with
* the parent group
*/
boolean getChecked[] = new boolean[getChildrenCount(mGroupPosition)];
// add getChecked[] to the mChildCheckStates hashmap using mGroupPosition as the key
mChildCheckStates.put(mGroupPosition, getChecked);
// set the check state of this position's checkbox based on the
// boolean value of getChecked[position]
childViewHolder.mCheckBox.setChecked(false);
}
childViewHolder.mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
getChecked[mChildPosition] = isChecked;
mChildCheckStates.put(mGroupPosition, getChecked);
} else {
boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
getChecked[mChildPosition] = isChecked;
mChildCheckStates.put(mGroupPosition, getChecked);
}
}
});
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
Log.d(_appLogTag, "Inside getChildrenCount");
//ShopCategory childList = mListDataChild.get(mCategorySectionVOs.get(groupPosition));
return mListDataChild.get(mCategorySectionVOs.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
Log.d(_appLogTag, "Inside getGroup");
return mCategorySectionVOs.get(groupPosition);
}
@Override
public int getGroupCount() {
Log.d(_appLogTag, "Inside getGroupCount");
return mCategorySectionVOs.size();
}
@Override
public long getGroupId(int groupPosition) {
Log.d(_appLogTag, "Inside getGroupId");
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// I passed a text string into an activity holding a getter/setter
// which I passed in through "ExpListGroupItems".
// Here is where I call the getter to get that text
//groupText = getGroup(groupPosition).getGroupText();
Log.d(_appLogTag, "Inside getGroupView");
groupText = ((ShopCategorySectionVO)getGroup(groupPosition)).getTitle();
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.group_item, null);
// Initialize the GroupViewHolder defined at the bottom of this document
groupViewHolder = new GroupViewHolder();
//groupViewHolder.mGroupText = (TextView) convertView.findViewById(R.id.groupTextView);
groupViewHolder.mGroupText = (TextView) convertView.findViewById(R.id.laptop_head);
convertView.setTag(groupViewHolder);
} else {
groupViewHolder = (GroupViewHolder) convertView.getTag();
}
groupViewHolder.mGroupText.setText(groupText);
return convertView;
}
@Override
public boolean hasStableIds() {
Log.d(_appLogTag, "Inside hasStableIds");
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
Log.d(_appLogTag, "Inside isChildSelectable");
return false;
}
public final class GroupViewHolder {
TextView mGroupText;
}
public final class ChildViewHolder {
TextView mChildText;
TextView mChildText2;
CheckBox mCheckBox;
}
}
请参阅我的片段类代码:ShopCategoryFragment.java
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.examples.testone.domain.CategorySection;
import com.examples.testone.domain.ShopCategory;
import com.examples.testone.domain.ShopCategoryParent;
import com.examples.testone.domain.ShopCategorySection;
import com.examples.testone.domain.response.ShopCategorySectionsRestResponse;
import com.examples.testone.network.volley.GsonRequest;
public class ShopCategoryFragment extends Fragment {
// private ShopCategorySectionListAdapter shopCategorySectionListAdapter;
private RequestQueue requestQueue;
private boolean requestRunning = false;
private String volleyRequestMode = "in";
final String _appLogTag = " - ShopCategoryFragment - ";
private List<ShopCategorySectionVO> shopCategorySectionVOs;
Map<ShopCategorySectionVO, List<ShopCategory>> myMapCollection;
private ExpandableListView expListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setRetainInstance(true);
Log.d(_appLogTag, "Inside onCreate");
//this.requestQueue = SmartShopVolleySettings.getRequestQueue();
this.requestQueue = Volley.newRequestQueue(getActivity());
startRequest();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(_appLogTag, "Inside onCreateView");
View viewHierarchy =
inflater.inflate(R.layout.fragment_explist, container, false);
// List View Settings
expListView =
(ExpandableListView) viewHierarchy.findViewById(R.id.laptop_list);
// getActivity(), this.shopCategorySectionVOs, this.collection );
expListView.setAdapter
(new ShopCategoryExpandibleListAdapter(getActivity(),
shopCategorySectionVOs, myMapCollection));
return viewHierarchy;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.d(_appLogTag, "Inside onViewCreated");
}
@Override
public void onDestroy() {
super.onResume();
Log.d(_appLogTag, "Inside onDestroy");
//this.requestQueue.cancelAll(this);
//this.requestRunning = false;
// cancelRequests();//Json shop lists
}
@Override
public void onPause() {
super.onPause();
Log.d(_appLogTag, "Inside onPause");
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// inflater.inflate(R.menu.simplemap_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
/*
* switch (item.getItemId()) {
*
* case R.id.simplemap_menu_info:
* SimpleDialogFragment.createBuilder(this.getActivity(),
* this.getActivity().getSupportFragmentManager())
* .setMessage(Html.fromHtml
* (getString(R.string.simplemap_info_details)))
* .setTitle(R.string.simplemap_info_title) .show(); return true; }
*/
return super.onOptionsItemSelected(item);
}
private void startRequest() {
Log.d(_appLogTag,"Inside on Start Request for getting the Shop Categories ");
if ( !requestRunning ) {
ShopCategoryFragment.this.requestRunning = true ;
String url = getString(R.string.shops_category_get_url, this.volleyRequestMode);
Log.d(_appLogTag, "Url for json is:" + url);
GsonRequest<ShopCategorySectionsRestResponse> jsonObjectRequest =
new GsonRequest<ShopCategorySectionsRestResponse>(Method.GET,
url, ShopCategorySectionsRestResponse.class,
null,
getShopsCategoriesRequestSuccessListener(),
getShopsCategoriesRequestErrorListener());
jsonObjectRequest.setShouldCache(false);
//Log.i(_appLogTag, " volley request Finished: "+
jsonObjectRequest.getBodyContentType() + " More: " + jsonObjectRequest.toString());
this.requestQueue.add(jsonObjectRequest);
} else if (BuildConfig.DEBUG) {
Log.i(_appLogTag, " volley request is already running");
}
/*myMapCollection = new LinkedHashMap<ShopCategorySectionVO,
List<ShopCategory>>(); // My Map
shopCategorySectionVOs = new ArrayList<ShopCategorySectionVO>(); // My Section Headers
List<ShopCategory> shopCategories = new ArrayList<ShopCategory>();
ShopCategorySectionVO shopCategorySectionVO1 =
new ShopCategorySectionVO("Dog", "icon", null);
shopCategorySectionVOs.add(shopCategorySectionVO1);
ShopCategory sc1 = new ShopCategory();
Title sc1t1 = new Title();
sc1t1.setEn("Tommy");
sc1.setTitle(sc1t1);
Description sc1d1 = new Description();
sc1d1.setEn("My Kuta Tommy");
sc1.setDescr(sc1d1);
shopCategories.add(sc1);
ShopCategory sc2 = new ShopCategory();
Title sc1t2 = new Title();
sc1t2.setEn("Boomer");
sc2.setTitle(sc1t2);
Description sc1d2 = new Description();
sc1d2.setEn("My Kuta Boomer");
sc2.setDescr(sc1d2);
shopCategories.add(sc2);
myMapCollection.put(shopCategorySectionVO1, shopCategories);*/
}
private Response.Listener<ShopCategorySectionsRestResponse>
getShopsCategoriesRequestSuccessListener() {
return new Response.Listener<ShopCategorySectionsRestResponse>() {
@Override
public void onResponse(ShopCategorySectionsRestResponse response) {
myMapCollection = new LinkedHashMap<ShopCategorySectionVO, List<ShopCategory>>();
shopCategorySectionVOs = new ArrayList<ShopCategorySectionVO>();
List<ShopCategory> shopCategories = new ArrayList<ShopCategory>();
Log.d(_appLogTag,"Ready for going inside");
for (CategorySection categorySection :response.getShop_category_sections()) {
Log.d(_appLogTag,"Inside Outer For");
ShopCategorySection catSection = categorySection.getShopCategorySection();
ShopCategorySectionVO shopCategorySectionVO =
new ShopCategorySectionVO
(catSection.getTitle(),catSection.getIcon(),
catSection.getBackcolor());
shopCategorySectionVOs.add(shopCategorySectionVO);
if (catSection.getShop_categories() != null &&
catSection.getShop_categories().size() > 0) {
Log.d(_appLogTag,"Inside Inner If");
for (ShopCategoryParent shopCategoryParent : catSection.getShop_categories()) {
Log.d(_appLogTag,"Inside Inner For");
ShopCategory shopCategory = shopCategoryParent.getShopCategory();
shopCategories.add(shopCategory);
}// End of child For
}// End of IF
myMapCollection.put(shopCategorySectionVO, shopCategories); // Filling of Map
}
// End of Outer For
requestRunning = false;
}
};
}
private Response.ErrorListener getShopsCategoriesRequestErrorListener() {
return new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(_appLogTag,"Inside on create Shops Request Error Listener ");
requestRunning = false;
}
};
}
}
import java.util.ArrayList;
导入java.util.LinkedHashMap;
导入java.util.List;
导入java.util.Map;
导入android.app.Fragment;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.Menu;
导入android.view.MenuInflater;
导入android.view.MenuItem;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ExpandableListView;
导入com.android.volley.Request.Method;
导入com.android.volley.RequestQueue;
导入com.android.volley.Response;
导入com.android.volley.VolleyError;
导入com.android.volley.toolbox.volley;
导入com.examples.testone.domain.CategorySection;
导入com.examples.testone.domain.ShopCategory;
导入com.examples.testone.domain.ShopCategoryParent;
导入com.examples.testone.domain.ShopCategorySection;
导入com.examples.testone.domain.response.ShopCategorySectionsResponse;
导入com.examples.testone.network.volley.GsonRequest;
公共类ShopCategoryFragment扩展片段{
//私有ShopCategorySectionListAdapter ShopCategorySectionListAdapter;
私有请求队列请求队列;
private boolean requestRunning=false;
私有字符串volleyRequestMode=“in”;
最后一个字符串_appLogTag=“-ShopCategoryFragment-”;
私人列表商店分类;
地图myMapCollection;
私有可扩展列表视图expListView;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//setRetainInstance(真);
Log.d(_appLogTag,“insideoncreate”);
//this.requestQueue=SmartShopVolleySettings.getRequestQueue();
this.requestQueue=Volley.newRequestQueue(getActivity());
startRequest();
}
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
Log.d(_appLogTag,“Inside onCreateView”);
视图层次结构=
充气机。充气(R.layout.fragment\u explist,容器,假);
//列表视图设置
解释视图=
(ExpandableListView)viewHierarchy.findViewById(R.id.laptop\U列表);
//getActivity(),this.shopCategorySectionVOs,this.collection);
expListView.setAdapter
(新的ShopCategoryExpandableListAdapter(getActivity()),
shopCategorySectionVOs,myMapCollection);
返回视图层次结构;
}
@凌驾
已创建视图上的公共void(视图,捆绑保存状态){
super.onViewCreated(视图,savedInstanceState);
Log.d(_appLogTag,“insideonviewcreated”);
}
@凌驾
公共空间{
super.onResume();
Log.d(_appLogTag,“onDestroy内部”);
//this.requestQueue.cancelAll(此);
//this.requestRunning=false;
//cancelRequests();//Json商店列表
}
@凌驾
公共无效暂停(){
super.onPause();
Log.d(_appLogTag,“内部暂停”);
}
@凌驾
创建选项菜单(菜单菜单,菜单充气机){
//充气机。充气(R.menu.simplemap_菜单,菜单);
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
/*
*开关(item.getItemId()){
*
*案例R.id.simplemap\u菜单\u信息:
*SimpleDialogFragment.createBuilder(this.getActivity(),
*此文件为.getActivity().getSupportFragmentManager())
*.setMessage(Html.fromHtml
*(getString(R.string.simplemap\u info\u details)))
*.setTitle(R.string.simplemap_info_title).show();返回true;}
*/
返回super.onOptionsItemSelected(项目);
}
私有void startRequest(){
Log.d(_appLogTag,“获取店铺类别的启动请求内部”);
如果(!requestRunning){
ShopCategoryFragment.this.requestRunning=true;
stringurl=getString(R.String.shops\u category\u get\u url,this.volleyRequestMode);
d(_appLogTag,“json的Url为:”+Url);
GsonRequest jsonObjectRequest=
新的GsonRequest(Method.GET,
url,ShopCategorySectionsRestrense.class,
无效的
GetShopScategoriesRequestsSuccessListener(),
getShopsCategoriesRequestErrorListener());
jsonObjectRequest.setShouldCache(false);
//Log.i(_appLogTag,“截击请求完成:”+
jsonObjectRequest.getBodyContentType()+“更多:”+jsonObjectRequest.toString());
this.requestQueue.add(jsonObjectRequest);
}else if(BuildConfig.DEBUG){
i(_appLogTag,“截击请求已在运行”);
}
/*myMapCollection=new LinkedHashMap();//我的地图
shopCategorySectionVOs=new ArrayList();//我的节标题
List shopCategories=新建ArrayList();
ShopCategorySectionVO shopCategorySectionVO1=
新ShopCategorySectionVO(“狗”,“图标”,空);
添加(shopCategorySectionVO1);
ShopCategory sc1=新ShopCategory();
标题sc1t1=新标题();
sc1t1.塞滕(“汤米”);
sc1.设置标题(sc1t1);
Description sc1d1=新的Description();
sc1d1.setEn(“我的库塔汤米”);
sc1.setDescr(sc1d1);
商店类别。添加(sc1);
ShopCategory sc2=新的ShopCategory();
标题sc1t2=新标题();
sc1t2.塞滕(“婴儿潮一代”);
sc2.设置标题(sc1t2);
说明sc1d2=新说明();
sc1d2.setEn(“我的库塔婴儿潮”);
sc2.setDescr(sc1d2);
添加(sc2);
myMapCollection.put(shopCategorySectionVO1,shopCategories)*/
}
私人回应。倾听者
GetShopScategoriesRequestsSuccessListener(){
返回新的Response.Listener(){
@凌驾
公共响应无效(ShopCategorySectionsRestreponse响应){
myMapCollection=新建LinkedHashMap();
shopCategorySectionVOs=新的ArrayList();
List shopCategories=新建ArrayList();
Log.d(_appLogTag,“准备进入内部”);
用于(类别)