2014-12-02 51 views
0

我有一个可扩展列表视图还通过我传递arraylist..I父项和子项只能看到第一个父child..by点击其他项目没有任何反应可扩展列表视图中只有一个孩子正显示出

的活动和可扩展列表视图适配器代码给出如下

\t expandableList = (ExpandableListView) findViewById(R.id.exlist); 
 
\t \t 
 
\t \t expandableList.setDividerHeight(2); 
 
\t \t expandableList.setGroupIndicator(null); 
 
\t \t expandableList.setClickable(true); 
 

 
\t \t setGroupParents(); 
 
\t \t setChildData(); 
 

 
\t \t MyExpandableAdapter exadapter = new MyExpandableAdapter(data); 
 
\t \t 
 
\t \t exadapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), this); 
 
\t \t expandableList.setAdapter(exadapter); 
 
// \t \t expandableList.setOnChildClickListener(this); 
 
\t \t expandableList.setOnChildClickListener(new OnChildClickListener() { 
 
\t \t \t 
 
\t \t \t @Override 
 
\t \t \t public boolean onChildClick(ExpandableListView parent, View v, 
 
\t \t \t \t \t int groupPosition, int childPosition, long id) { 
 
\t \t \t \t // TODO Auto-generated method stub 
 
\t \t \t \t return false; 
 
\t \t \t } 
 
\t \t });

package com.javacodegeeks.android.loginapp; 
 

 
import java.util.ArrayList; 
 

 
import android.app.Activity; 
 
import android.view.LayoutInflater; 
 
import android.view.View; 
 
import android.view.View.OnClickListener; 
 
import android.view.ViewGroup; 
 
import android.widget.BaseExpandableListAdapter; 
 
import android.widget.CheckedTextView; 
 
import android.widget.TextView; 
 
import android.widget.Toast; 
 

 

 
public class MyExpandableAdapter extends BaseExpandableListAdapter { 
 

 
\t private Activity activity; 
 
\t private ArrayList<Object> childtems; 
 
\t private String parent; 
 
\t private LayoutInflater inflater; 
 
\t private ArrayList<String> parentItems; 
 
\t ArrayList<ObjectModelClass> data; 
 
\t ArrayList<ArrayList<String>> nodes = new ArrayList<ArrayList<String>>(); 
 

 
\t ArrayList<String> childs=new ArrayList<String>(); 
 
\t public MyExpandableAdapter(ArrayList<String> parents, ArrayList<Object> childern) { 
 
\t \t this.parentItems = parents; 
 
\t \t this.childtems = childern; 
 
\t } 
 

 
\t public MyExpandableAdapter(ArrayList<ObjectModelClass> data) { 
 
\t \t 
 
\t \t this.data=data; 
 
\t \t 
 
\t \t 
 
\t } 
 

 
\t public void setInflater(LayoutInflater inflater, Activity activity) { 
 
\t \t this.inflater = inflater; 
 
\t \t this.activity = activity; 
 
\t } 
 

 
\t 
 
\t 
 
\t @Override 
 
\t public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
 
\t \t 
 
\t \t String child = (String) getChild(groupPosition, childPosition); 
 
\t \t ChildViewHolder childHolder; 
 
\t \t 
 
\t \t if (convertView == null) { 
 
\t \t \t childHolder \t = \t new ChildViewHolder(); 
 
\t \t \t convertView = inflater.inflate(R.layout.group, null); 
 
\t \t \t childHolder.textView = (TextView) convertView.findViewById(R.id.title); 
 
\t \t \t childHolder.textPrice = (TextView) convertView.findViewById(R.id.price); 
 
\t \t \t convertView.setTag(childHolder); 
 
\t \t } 
 
\t \t else 
 
\t \t { 
 
\t \t \t childHolder \t = \t (ChildViewHolder) convertView.getTag(); 
 
\t \t } 
 
\t \t 
 
\t \t 
 
\t \t childHolder.textView.setText(child); 
 
\t \t 
 
\t \t 
 
\t \t 
 
\t \t return convertView; 
 
\t } 
 
\t 
 
\t private static class ChildViewHolder 
 
\t { 
 
\t \t TextView textView; 
 
\t \t TextView textPrice; 
 
\t } 
 
\t @Override 
 
\t public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
 
\t \t 
 
\t \t if (convertView == null) { 
 
\t \t \t convertView = inflater.inflate(R.layout.row_ex, null); 
 
\t \t } 
 
\t \t 
 
\t \t ((CheckedTextView) convertView).setText(data.get(groupPosition).getTitle()); 
 
\t \t ((CheckedTextView) convertView).setChecked(isExpanded); 
 
\t \t 
 
\t \t return convertView; 
 
\t } 
 

 
\t @Override 
 
\t public Object getChild(int groupPosition, int childPosition) { 
 
\t \t return data.get(groupPosition).getChildren().get(childPosition); 
 
\t } 
 

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

 
\t 
 
\t @Override 
 
\t public int getChildrenCount(int groupPosition) { 
 
\t \t System.out.println(groupPosition); 
 
\t \t return data.get(groupPosition).getChildren().size(); 
 
\t } 
 

 
\t @Override 
 
\t public Object getGroup(int groupPosition) { 
 
\t \t return data.get(groupPosition); 
 
\t } 
 

 
\t @Override 
 
\t public int getGroupCount() { 
 
\t \t return data.size(); 
 
\t } 
 

 

 

 
\t 
 
\t 
 
\t 
 

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

 
\t @Override 
 
\t public boolean isChildSelectable(int groupPosition, int childPosition) { 
 
\t \t return false; 
 
\t } 
 

 
\t @Override 
 
\t public long getGroupId(int groupPosition) { 
 
\t \t // TODO Auto-generated method stub 
 
\t \t return 0; 
 
\t } 
 

 
}

回答

0

改变这一点:

@Override 
public Object getChild(int groupPosition, int childPosition) { 
    return data.get(groupPosition).getChildren().get(childPosition); 
} 
+0

我改变了代码...还是一样的问题 – 2014-12-02 12:03:12

+0

PLZ检查我的编辑 – 2014-12-02 12:19:12

+0

类型不匹配:当我改变了代码 – 2014-12-02 12:22:14

0

改变孩子数到data.get(groupPosition).getChildren()大小();

相关问题