1

У меня есть многоуровневое расширяемое listview. Но большие дочерние элементы не полностью видны в моем случае. Также я знаю, что это происходит в случае listview. Но в расширяемом listview я не знаю, что его Пожалуйста, помогите мне показать полного внука. моя основная деятельностьРасширяемый дочерний набор listview не полностью виден

public class MainActivity extends Activity 
{ 
    ExpandableListView explvlist; 
    TextView ui_hot = null; 
    int hot_number = 0; 
    // private ExpandListAdapter ExpAdapter; 
    private ArrayList<Group> ExpListItems; 
    private ExpandableListView ExpandList; 
    // private SliderLayout mDemoSlider; 
    Intent intent = null; 
    RequestQueue requestQueue1, requestQueue2; 
    int[] firstcatid = null,secondcatid = null; 
    String firsttitle[] = null,secondtitle[] = null; 
    int j = 0; 
    ArrayList<Group> list,list2,list3; 
    CustExpListview SecondLevelexplv; 
    ExpandableListView elv; 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     requestQueue1 = Volley.newRequestQueue(getApplicationContext()); 
     JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, "http://www.ezyret.com/cntrldata/ezproductfristcategory.php", 
       new Response.Listener<JSONObject>() { 
        @Override 
        public void onResponse(JSONObject response) { 

         try { 
          list = new ArrayList<Group>(); 
          JSONArray ja = response.getJSONArray("hi"); 
          JSONArray ja2 = response.getJSONArray("hi2"); 
          JSONArray ja3 = response.getJSONArray("hi3"); 
          firsttitle = new String[ja.length()]; 
          firstcatid = new int[ja.length()]; 
          JSONObject jsonObject2=null,jsonObject3=null,jsonObject; 
          for (int i = 0; i < ja.length(); i++) { 

           jsonObject = ja.getJSONObject(i); 


           // Log.e("hie",jsonObject2.getInt("second_category_id")+""); 
           //jsonObject3 = ja3.getJSONObject(i); 
           firstcatid[i] = jsonObject.getInt("first_category_id"); 
           firsttitle[i] = jsonObject.getString("first_category_name"); 
          } 
          secondcatid=new int[ja2.length()]; 
          for(int i =0;i<ja2.length();i++){ 
           jsonObject2 = ja2.getJSONObject(i); 
           secondcatid[i]=jsonObject2.getInt("second_category_id"); 
          } 
          for(int i = 0;i<ja.length();i++){ 
           Group gru = new Group(); 
           gru.setName(firsttitle[i]); 
           list2 = new ArrayList<Group>(); 
           for(int j=0;j<ja2.length();j++){ 
            Group gru2 = new Group(); 
            jsonObject2 = ja2.getJSONObject(j); 

            //Toast.makeText(getApplicationContext(),jsonObject2.getInt("second_category_id"),Toast.LENGTH_SHORT).show(); 
            if(firstcatid[i]==jsonObject2.getInt("first_category_id")){ 
             gru2.setName(jsonObject2.getString("second_category_name")); 
             list3= new ArrayList<Group>(); 
             for(int k=0;k<ja3.length();k++){ 
              Group gru3= new Group(); 
              jsonObject3 = ja3.getJSONObject(k); 
              if(secondcatid[j]==jsonObject3.getInt("second_category_id")){ 
               Log.e("hie", jsonObject2.getInt("second_category_id") + ""); 
               gru3.setName(jsonObject3.getString("third_category_name")); 
               list3.add(gru3); 
              } 
              gru2.setItems(list3); 

             } 


             list2.add(gru2); 
            } 


           } 
           gru.setItems(list2); 
           list.add(gru); 
          } 

          // Toast.makeText(getApplicationContext(),url[2],Toast.LENGTH_SHORT).show(); 
          //output.setText(data); 
          ExpListItems = list; 
          explvlist = (ExpandableListView)findViewById(R.id.ParentLevel); 
          explvlist.setAdapter(new ParentLevel(getApplicationContext(),ExpListItems,ExpListItems,list3)); 
          //ExpAdapter = new ExpandListAdapter(getApplicationContext(), ExpListItems); 
          // ExpandList.setAdapter(ExpAdapter); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } 

       }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError error) { 
         Log.e("Volley", error.toString()); 

        } 
       } 
     ); 
     requestQueue1.add(jsonObjectRequest); 


    } 

    public class ParentLevel extends BaseExpandableListAdapter { 
     private Context context; 
     private ArrayList<Group> groups,childgroup,childgroup2,a1; 

     @Override 
     public ArrayList<Group> getChild(int groupPosition, int childPosition) { 
      ArrayList<Group> chList = groups.get(groupPosition).getItemz(); 
      return chList; 
     } 

     public ParentLevel(Context context, ArrayList<Group> groups,ArrayList<Group> groups2,ArrayList<Group> groups3) { 
      this.context = context; 
      this.groups = groups; 
      this.childgroup=groups2; 
      this.childgroup2=groups3; 
     } 

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

     @Override 
     public View getChildView(int groupPosition, int childPosition, 
           boolean isLastChild, View convertView, ViewGroup parent) { 
     //Group child = (Group) getChild(groupPosition, childPosition); 
      ArrayList<Group> ch=(ArrayList<Group>)getChild(groupPosition, childPosition); 
      SecondLevelexplv = (CustExpListview)convertView; 
      if (convertView == null) { 
       SecondLevelexplv=new CustExpListview(MainActivity.this); 
      } 
      //child.setItems(childgroup); 
      //requestQueue1 = Volley.newRequestQueue(getApplicationContext()); 

      SecondLevelAdapter adapter=new SecondLevelAdapter(context, ch); 

      SecondLevelexplv.setAdapter(adapter); 
      SecondLevelexplv.setGroupIndicator(null); 
      return SecondLevelexplv; 
     } 

     @Override 
     public int getChildrenCount(int groupPosition) { 
      ArrayList<Group> chList = groups.get(groupPosition).getItemz(); 
      if(!(chList==null)) 
       return 1; 
      else return 0; 
     } 

     @Override 
     public Object getGroup(int groupPosition) { 
      return groups.get(groupPosition); 
     } 

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

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

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

     Group group = (Group) getGroup(groupPosition); 
     if(convertView==null) 

     { 
      LayoutInflater inf = (LayoutInflater) context 
        .getSystemService(context.LAYOUT_INFLATER_SERVICE); 
      convertView = inf.inflate(R.layout.group_item, null); 
     } 

     TextView tv = (TextView) convertView.findViewById(R.id.group_name); 
     tv.setPadding(10, 7, 7, 7); 

      tv.setText(group.getName()); 
     ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView); 
     if(!(group.getItems()==null)) 

     { 
      if (!group.getItems().isEmpty()) { 
       if (isExpanded) { 
        tv.setTypeface(null, Typeface.BOLD); 
        imageView.setBackgroundResource(R.drawable.ic_action_minus); 
       } else { 
        imageView.setBackgroundResource(R.drawable.ic_action_add); 
        tv.setTypeface(null, Typeface.NORMAL); 
       } 
      } else imageView.setVisibility(View.INVISIBLE); 
     } 

     return convertView; 


    } 

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

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

    public class CustExpListview extends ExpandableListView 
    { 

     int intGroupPosition, intChildPosition, intGroupid; 

     public CustExpListview(Context context) 
     { 
      super(context); 
     } 

     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
     { 
      widthMeasureSpec = MeasureSpec.makeMeasureSpec(960, MeasureSpec.AT_MOST); 
      heightMeasureSpec = MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST); 
      super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
     } 
    } 

    public class SecondLevelAdapter extends BaseExpandableListAdapter { 
     int i = 0; 
     private Context context; 
     private ArrayList<Group> groups; 
     private int gr; 

     public SecondLevelAdapter(Context context, ArrayList<Group> groups) { 
      this.context = context; 
      this.groups = groups; 


     } 

     @Override 
     public Object getChild(int groupPosition, int childPosition) { 
      ArrayList<Group> chList = groups.get(groupPosition).getItems(); 
      return chList.get(childPosition); 
     } 

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

     @Override 
     public View getChildView(int groupPosition, int childPosition, 
           boolean isLastChild, View convertView, ViewGroup parent) { 

      Group child = (Group) getChild(groupPosition, childPosition); 

      if (convertView == null) { 
       LayoutInflater infalInflater = (LayoutInflater) context 
         .getSystemService(context.LAYOUT_INFLATER_SERVICE); 
       convertView = infalInflater.inflate(R.layout.group_item, null); 
      } 
      TextView tv = (TextView) convertView.findViewById(R.id.group_name); 

      tv.setText(child.getName().toString()); 

      //Toast.makeText(context,child.getName().toString()+"hi",Toast.LENGTH_SHORT).show(); 
      return convertView; 
     } 

     @Override 
     public int getChildrenCount(int groupPosition) { 
      ArrayList<Group> chList = groups.get(groupPosition).getItems(); 
      if (!(chList == null)) 
       return chList.size(); 
      else return 0; 
     } 

     @Override 
     public Object getGroup(int groupPosition) { 
      return groups.get(groupPosition); 
     } 

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

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

     @Override 
     public View getGroupView(int groupPosition, boolean isExpanded, 
           View convertView, ViewGroup parent) { 
      Group group = (Group) getGroup(groupPosition); 
      if (convertView == null) { 
       LayoutInflater inf = (LayoutInflater) context 
         .getSystemService(context.LAYOUT_INFLATER_SERVICE); 
       convertView = inf.inflate(R.layout.group_item, null); 
      } 
      TextView tv = (TextView) convertView.findViewById(R.id.group_name); 

      tv.setText(group.getName()); 
      ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView); 
      if (!(group.getItems() == null)) { 
       if (!group.getItems().isEmpty()) { 
        if (isExpanded) { 
         tv.setTypeface(null, Typeface.BOLD); 
         imageView.setBackgroundResource(R.drawable.ic_action_minus); 
        } else { 
         imageView.setBackgroundResource(R.drawable.ic_action_add); 
         tv.setTypeface(null, Typeface.NORMAL); 
        } 
       } else imageView.setVisibility(View.INVISIBLE); 
      } 

      return convertView; 
     } 

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

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

Моя активность XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ExpandableListView 
     android:layout_width="fill_parent" 
     android:id="@+id/ParentLevel" 
     android:groupIndicator="@null" 
     android:layout_height="fill_parent"> 

    </ExpandableListView> 



</LinearLayout> 

моя группа элемент XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:padding="10dp" 
    android:weightSum="1"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:layout_gravity="right" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" /> 

    <TextView 
     android:id="@+id/group_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="15dp" 
     android:textColor="#010101" 
     android:text="e" /> 

</RelativeLayout> 

ПИК enter image description here

+0

сообщение 'xml' пожалуйста. –

+0

Хорошо. Извините за неудобства. Спасибо –

+0

'android: textSize =" 15dp "' должно быть 'sp' –

ответ

0
Better You can use ScrollView-->LinearLayout--> ExpandableListView 

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_expandable_scroll_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <LinearLayout android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 

        <ExpandableListView android:layout_width="fill_parent" 
             android:id="@+id/ParentLevel" 
             android:groupIndicator="@null" 
             android:layout_height="fill_parent"> 
        </ExpandableListView> 
    </LinearLayout> 
</ScrollView>