展开式清单检视setOnChildClickListener无法运作 [英] Expandable list view setOnChildClickListener not working

查看:166
本文介绍了展开式清单检视setOnChildClickListener无法运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用可扩展的列表视图.我在时光方法内给了setOnChildClickListener, 但是setOnChildClickListener无法正常工作,我正在SO中搜索解决方案,但找不到任何解决方案.在这里给我我所做的

I m using an expandable listview. i given setOnChildClickListener inside the onceate method, but the setOnChildClickListener is not working, i was searching for the solution in SO but i cannot find any solution. here giving what i had done

  public class MenuActivity extends Activity{
    ArrayList<MyObject> CatList = new ArrayList<MyObject>();
    ArrayList<Object> childItem = new ArrayList<Object>();
    ExpandableListView ExList;

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
             setContentView(R.layout.menuactivity);

         ExList=(ExpandableListView) findViewById(R.id.lvMenu) ;


           ExList.setOnChildClickListener(new OnChildClickListener() {

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

                  ShowItem(CatList.get(childPosition).getId());

                  Toast.makeText(context, ""+CatList.get(childPosition).getId(), 1).show();
                // TODO Auto-generated method stub
                return false;
            }
        });

    }


 public void ShowItem(int id)
 {
   // do something
 }

  public class ElistAdapt extends BaseExpandableListAdapter  {

 public ArrayList<MyObject> groupItem, tempGrpChild;
 public ArrayList<Object> Childtem = new ArrayList<Object>();
 public LayoutInflater minflater;
 public Activity activity;


 public ElistAdapt(ArrayList<MyObject> GroupList, ArrayList<Object> childItem) {
  groupItem = GroupList;
  this.Childtem = childItem;
 }

 public void setInflater(LayoutInflater mInflater, Activity act) {
  this.minflater = mInflater;
  activity = act;
 }

 @Override
 public Object getChild(int groupPosition, int childPosition) {
  return null;
 }

 @Override
 public long getChildId(int groupPosition, int childPosition) {
  return 0;
 }

 @Override
 public View getChildView(final int groupPosition, final int childPosition,
   boolean isLastChild, View convertView, ViewGroup parent) {
  tempGrpChild = (ArrayList<MyObject>) Childtem.get(groupPosition);
  TextView text = null;
  TextView text2 = null;
  if (convertView == null) {
   convertView = minflater.inflate(R.layout.childrow, null);
  }
  text = (TextView) convertView.findViewById(R.id.textView1);
  text2 = (TextView) convertView.findViewById(R.id.textView2);
  text.setText(tempGrpChild.get(childPosition).getName());
  text2.setText(tempGrpChild.get(childPosition).getPrice());

  return convertView;  
 }

 @Override
 public int getChildrenCount(int groupPosition) {
  return ((ArrayList<MyObject>) Childtem.get(groupPosition)).size();
 }

 @Override
 public Object getGroup(int groupPosition) {
//  return null;
  return this.groupItem.get(groupPosition);
 }

 @Override
 public int getGroupCount() {
  return groupItem.size();
 }

 @Override
 public void onGroupCollapsed(int groupPosition) {
  super.onGroupCollapsed(groupPosition);
 }

 @Override
 public void onGroupExpanded(int groupPosition) {
  super.onGroupExpanded(groupPosition);
 }

 @Override
 public long getGroupId(int groupPosition) {
  return 0;
 }

 @Override
 public View getGroupView(final int groupPosition, boolean isExpanded,
   View convertView, ViewGroup parent) {

     if (convertView == null) 
          {
            LayoutInflater inflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.grouprow, null);
           }

           TextView tvGroupName = (TextView) convertView.findViewById(R.id.textView1);
           tvGroupName.setText(groupItem.get(groupPosition).getName());


  return convertView;
 }

 @Override
 public boolean hasStableIds() {
  return false;
 }

 @Override
 public boolean isChildSelectable(int groupPosition, int childPosition) {
  return true;
 }

}
 }

请帮助我为什么setOnChildClickListener无法正常工作

please help me why setOnChildClickListener is not working

推荐答案

在您的适配器类中,返回isChildSelectable()方法中的真实值.

In your adapter class return the true value in isChildSelectable() method.

这篇关于展开式清单检视setOnChildClickListener无法运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆