2016-10-26 32 views
6

Vì vậy, tôi đã thực hiện ứng dụng này để phân tích giấc mơ và hoạt động rất tốt trên điện thoại, nhưng trên máy tính bảng, thông tin trong các trình khám phá được pha trộn như bạn có thể thấy trong hình bên dưới.Các mục của ExpandableListView được pha trộn

Tức là, khi bạn nhấp vào nhóm, nó sẽ ẩn/hiển thị con của nó, nhưng như bạn thấy, trên máy tính bảng, nó chỉ tiếp tục vẽ thông tin trên mặt khác, như màn hình sẽ không làm mới nội dung của nó không có ý tưởng phải làm gì, do đó yêu cầu bạn giúp đỡ.

device-2016-10-26-094550.png

Cách bố trí container:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="10dp"> 


    <ExpandableListView 
     android:id="@+id/sExpList" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:groupIndicator="@null" /> 

    <!-- FOR PORTRAIT LAYOUTS !--> 
    <FrameLayout 
     android:id="@+id/adLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center_horizontal" 
     android:layout_marginTop="5dp" 
     android:baselineAligned="false" 
     android:orientation="vertical"/> 
</LinearLayout> 

Mã yếu tố nhóm:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    > 

    <TextView 
     android:id="@+id/textGroup" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     android:layout_marginTop="20dp" 
     android:layout_weight="1" 
     android:textStyle="bold" 
     android:textSize="@dimen/text_normal_size" /> 

    <ImageButton 

     android:id="@+id/sExp_BtnAdd" 
     android:layout_width="@dimen/btns_heigh" 
     android:layout_height="@dimen/btns_heigh" 
     android:layout_gravity="center_vertical" 
     android:contentDescription="" 
     android:focusable="false" 
     android:scaleType="centerCrop" 
     android:src="?attr/img_add" /> 

</LinearLayout> 

Mã phần tử con:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent"> 

    <TextView 
      android:id="@+id/textChild" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="20dp" 
      android:layout_marginTop="20dp" 
      android:textColor="@android:color/white" 
      android:layout_weight="1" 
     android:textSize="@dimen/text_normal_size" /> 

    <ImageButton 
      android:layout_width="@dimen/btns_heigh" 
      android:layout_height="@dimen/btns_heigh" 
      android:id="@+id/sExp_BtnEdit" 
      android:layout_gravity="center_vertical" 
      android:src="?attr/img_edit" 
      android:scaleType="centerCrop" 
      android:focusable="false" 
     android:layout_marginRight="@dimen/btns_heigh" /> 


</LinearLayout> 

đang Hoạt động:

import android.content.Context; 
import android.content.Intent; 
import android.content.res.Configuration; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.ContextMenu; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseExpandableListAdapter; 
import android.widget.ExpandableListView; 
import android.widget.ImageButton; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 

import java.util.ArrayList; 

/** 
* Created with IntelliJ IDEA. 
* User: Movsar Bekaev 
* Date: 11.06.13 
* Time: 7:30 
* To change this template use File | Settings | File Templates. 
*/ 
public class ActSignsManager extends cbActivity { 


    ExpandableListView expListView; 

    int selected_type; 
    String[] cats; 
    ArrayList<xSign> MySigns; 
    _sManagerExpAdapter adapter; 


    String[] catsMind; 
    String[] catsAction; 
    String[] catsForm; 
    String[] catsCircumstances; 


    private void cInitialization() { 
     setContentView(R.layout.alay_signs_manager); 

     catsMind = getResources().getStringArray(R.array.smanager_cats_mind); 
     catsAction = getResources().getStringArray(R.array.smanager_cats_action); 
     catsForm = getResources().getStringArray(R.array.smanager_cats_form); 
     catsCircumstances = getResources().getStringArray(R.array.smanager_cats_circumstances); 

     expListView = (ExpandableListView) findViewById(R.id.sExpList); 

     newSignFunc(); 
     readSigns(); 
     expFiller(); 
     adapter.notifyDataSetChanged(); 


     expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 
      public boolean onChildClick(ExpandableListView parent, View v, 
             int groupPosition, int childPosition, long id) { 
       String s = MySigns.get(SignIndexAt(selected_type, groupPosition, adapter.getChild(groupPosition, childPosition).toString())).getTitle(); 
       Toast.makeText(ActSignsManager.this, String.valueOf(s), Toast.LENGTH_LONG).show(); 
       return false; 
      } 
     }); 
     expListView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { 

      @Override 
      public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { 
       String menuItems[]; 
       ExpandableListView.ExpandableListContextMenuInfo info = 
         (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; 
       int type = ExpandableListView.getPackedPositionType(info.packedPosition); 
       int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
       int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); 

       if (type == 0) { 

        menuItems = getResources().getStringArray(R.array.exp_menu_ongroup); 
        menu.setHeaderTitle(adapter.getGroupText(groupPos)); 
        for (int i = 0; i < menuItems.length; i++) { 
         menu.add(Menu.NONE, i, i, menuItems[i]); 
        } 
       } 
       if (type == 1) { 
        String s = adapter.getChild(groupPos, childPos).toString(); 
        menuItems = getResources().getStringArray(R.array.exp_menu_onchild); 
        menu.setHeaderTitle(s); 
        for (int i = 0; i < menuItems.length; i++) { 
         menu.add(Menu.NONE, i, i, menuItems[i]); 
        } 
       } 
      } 
     }); 

    } 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setTheme(R.style.DarkTheme); 
     cInitialization(); 

    } 

    @Override 
    public boolean onContextItemSelected(MenuItem item) { 
     ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) item.getMenuInfo(); 
     int menuItemIndex = item.getItemId(); 
     int type = ExpandableListView.getPackedPositionType(info.packedPosition); 
     int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); 
     int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); 

     if (type == 0) { 

      switch (menuItemIndex) { 
       case 0: 
        Intent i = new Intent(ActSignsManager.this, ActSignsAddNew.class); 
        ps_int_params.put("Type", selected_type); 
        ps_string_arr_params.put("Categories", cats); 
        ps_int_params.put("Selected_Item", groupPos); 

        if (IS_FREE_VERSION && MySigns.size() > 69) 
         Toast.makeText(ActSignsManager.this, getString(R.string.ruefully_you_cant_add_another_sign), Toast.LENGTH_LONG).show(); 
        else startActivity(i); 

        break; 
      } 
     } 
     if (type == 1) { 
      int index = SignIndexAt(selected_type, groupPos, adapter.getChild(groupPos, childPos).toString()); 

      switch (menuItemIndex) { 
       case 0: 
        //  Toast.makeText(sManager.this, "edit", 5000).show(); 
        Intent i = new Intent(ActSignsManager.this, ActSignsAddNew.class); 

        ps_int_params.put("ID", MySigns.get(index).getID()); 
        ps_string_params.put("Name", MySigns.get(index).getTitle()); 
        ps_int_params.put("Type", MySigns.get(index).getType()); 
        ps_int_params.put("Category", MySigns.get(index).getCategory()); 
        ps_string_params.put("Note", MySigns.get(index).getNote()); 
        ps_string_arr_params.put("Categories", cats); 


        startActivity(i); 
        break; 
      } 
     } 

     return true; 
    } 

    // нажатие на элемент 

    void newSignFunc() { 
     String type = ps_string_params.get("Type"); 
     if (type.equals("Mind")) { 
      cats = catsMind; 
      selected_type = 0; 
     } 
     if (type.equals("Action")) { 
      cats = catsAction; 
      selected_type = 1; 
     } 
     if (type.equals("Form")) { 
      cats = catsForm; 
      selected_type = 2; 
     } 
     if (type.equals("Circumstances")) { 
      cats = catsCircumstances; 
      selected_type = 3; 
     } 

    } 

    private void readSigns() { 
     MySigns = new ArrayList<xSign>(); 

     Cursor c = ps_db.query(const_tbl_signs, null, null, null, null, null, null); 
     if (c != null) { 
      if (c.moveToFirst()) { 
       do { 
        xSign iSingleSign = new xSign(); 
        iSingleSign.setID(c.getInt(DBI_SIGNS_ID)); 
        iSingleSign.setHash(c.getString(DBI_SIGNS_HASH)); 
        iSingleSign.setTitle(c.getString(DBI_SIGNS_TITLE)); 
        iSingleSign.setType(c.getInt(DBI_SIGNS_TYPE)); 
        iSingleSign.setCategory(c.getInt(DBI_SIGNS_CATEGORY)); 
        iSingleSign.setNote(c.getString(DBI_SIGNS_NOTE)); 
        MySigns.add(iSingleSign); 
        Log.d("777", iSingleSign.getID() + "||| cat:" + iSingleSign.getCategory() + "||| type:" + iSingleSign.getType()); 
       } while (c.moveToNext()); 
       c.close(); 
      } else 
       Log.d("777", "0 rows"); 
     } 


    } 


    private int SignIndexAt(int type, int category, String name) { 
     boolean exist = false; 
     int index = -1; 
     for (int i = 0; i < this.MySigns.size(); i++) { 
      if (this.MySigns.get(i).getTitle().equals(name) && this.MySigns.get(i).getCategory() == category && this.MySigns.get(i).getType() == type) { 
       index = i; 
       exist = true; 
      } 
     } 
     if (exist) { 
      return index; 
     } else { 
      return 999999; 
     } 
    } 

    private boolean removeSign(int index) { 
     ps_db.delete(const_tbl_signs, "id = " + MySigns.get(index).getID(), null); 

     Toast.makeText(ActSignsManager.this, getString(R.string.messages_sign_removed), Toast.LENGTH_LONG).show(); 
     // Refresh main activity upon close of dialog box 

     readSigns(); 
     expFiller(); 

     adapter.notifyDataSetChanged(); 
     return true; 
    } 

    private void expFiller() { 
     ArrayList<String> tmp; 
     ArrayList<ArrayList<String>> groups = new ArrayList<ArrayList<String>>(); 
     for (int i = 0; i < cats.length; i++) { 
      tmp = new ArrayList<String>(); 
      for (xSign sign : MySigns) { 
       if (sign.getCategory() == i && sign.getType() == selected_type) 
        tmp.add(sign.getTitle()); 
      } 
      groups.add(tmp); 
     } 
     //Создаем адаптер и передаем context и список с данными 
     adapter = new _sManagerExpAdapter(this, cats, groups); 
     expListView.setAdapter(adapter); 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     cInitialization(); 
     showAds(); 
    } 

    @Override 
    public void onConfigurationChanged(Configuration newConfig) { 
     super.onConfigurationChanged(newConfig); 
     cInitialization(); 
     showAds(); 
    } 

    public class _sManagerExpAdapter extends BaseExpandableListAdapter { 

     private ArrayList<ArrayList<String>> mGroups; 
     private Context mContext; 
     private String[] cats; 

     public _sManagerExpAdapter(Context context, String[] categories, ArrayList<ArrayList<String>> groups) { 
      mContext = context; 
      mGroups = groups; 
      cats = categories; 
     } 


     public String getGroupText(int groupPosition) { 
      return cats[groupPosition]; 
     } 

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

     @Override 
     public int getChildrenCount(int groupPosition) { 
      return mGroups.get(groupPosition).size(); 
     } 

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

     @Override 
     public Object getChild(int groupPosition, int childPosition) { 
      return mGroups.get(groupPosition).get(childPosition); 
     } 

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

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

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

     @Override 
     public View getGroupView(int groupPosition, boolean isExpanded, View convertView, 
           ViewGroup parent) { 
      if (convertView == null) { 
       LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       convertView = inflater.inflate(R.layout.s_exp_group_view, null); 
      } 

      if (isExpanded) { 
       //Изменяем что-нибудь, если текущая Group раскрыта 
      } else { 
       //Изменяем что-нибудь, если текущая Group скрыта 
      } 

      TextView textGroup = (TextView) convertView.findViewById(R.id.textGroup); 
      textGroup.setText(cats[groupPosition] + " [" + String.valueOf(this.getChildrenCount(groupPosition)) + "]"); 

      ImageView btnAddSigns = (ImageView) convertView.findViewById(R.id.sExp_BtnAdd); 
      btnAddSigns.setFocusable(false); 
      final int gPos = groupPosition; 

      btnAddSigns.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        Intent i = new Intent(ActSignsManager.this, ActSignsAddNew.class); 
        ps_int_params.put("Type", selected_type); 
        ps_string_arr_params.put("Categories", cats); 
        ps_int_params.put("Selected_Item", gPos); 

        if (IS_FREE_VERSION && MySigns.size() > 69) 
         Toast.makeText(ActSignsManager.this, getString(R.string.ruefully_you_cant_add_another_sign), Toast.LENGTH_LONG).show(); 
        else startActivity(i); 
       } 
      }); 

      return convertView; 

     } 

     @Override 
     public View getChildView(int groupPosition, int childPosition, boolean isLastChild, 
           View convertView, ViewGroup parent) { 
      if (convertView == null) { 
       LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       convertView = inflater.inflate(R.layout.s_exp_child_view, null); 
      } 

      TextView textChild = (TextView) convertView.findViewById(R.id.textChild); 
      textChild.setText(mGroups.get(groupPosition).get(childPosition)); 

      final int index = SignIndexAt(selected_type, groupPosition, adapter.getChild(groupPosition, childPosition).toString()); 

      ImageView btnEditSign = (ImageView) convertView.findViewById(R.id.sExp_BtnEdit); 
      btnEditSign.setFocusable(false); 


      btnEditSign.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        Intent i = new Intent(ActSignsManager.this, ActSignsAddNew.class); 

        ps_int_params.put("ID", MySigns.get(index).getID()); 
        ps_string_params.put("Name", MySigns.get(index).getTitle()); 
        ps_int_params.put("Type", MySigns.get(index).getType()); 
        ps_int_params.put("Category", MySigns.get(index).getCategory()); 
        ps_string_params.put("Note", MySigns.get(index).getNote()); 
        ps_string_arr_params.put("Categories", cats); 
        startActivity(i); 
       } 
      }); 


      return convertView; 
     } 

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


} 

Trả lời

0

Vâng tôi đã tìm thấy câu trả lời, và ở đây là - bạn nên đặt nền cho bố cục một cách rõ ràng và điều quan trọng là bạn đặt nó thành phần tử khám phá hoặc gốc, nó chỉ phải được đặt.

Nó không bắt đầu hoạt động với bất kỳ giải pháp được đề xuất nào trừ khi tôi đã đặt nền trong bố cục của hoạt động chứa người khám phá.

Câu hỏi thú vị - tại sao tính năng này hoạt động ?!

0

Tôi có thể làm cho nó hoạt động nhưng lỗi tôi nhận được hơi khác so với của bạn.

Khi tôi cố gắng sử dụng bố trí của bạn (trừ các nguồn lực tôi không có) các ImageButton s trong cả group_element.xmlchild_element.xml được bằng cách nào đó chụp MotionEvent s trong toàn bộ hàng (khi họ không nên) và trong trường hợp của tôi nó là rối tung với việc mở rộng bố cục.

Giải pháp: Tôi chỉ hai số ImageButton cho hai ImageView và xây dựng OnTouchListener giây cho hai chế độ xem. Như bạn có thể thấy nó đang chạy trên bộ mô phỏng Nexus 7.

Vì tôi không có tập dữ liệu và quan trọng nhất là mã bộ chuyển đổi Tôi không thể chắc chắn rằng điều này sẽ khắc phục được sự cố của bạn.

enter image description here

Ps trong trường hợp bạn đang quan tâm tôi đã thử nghiệm XML của bạn về phiên bản tùy biến của các ví dụ bộ chuyển đổi JournalDev về ExpandableListViews:

import java.util.HashMap; 
import java.util.List; 
import android.content.Context; 
import android.graphics.Typeface; 
import android.view.LayoutInflater; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseExpandableListAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 
public class CustomExpandableListAdapter extends BaseExpandableListAdapter { 

    private Context context; 
    private List<String> expandableListTitle; 
    private HashMap<String, List<String>> expandableListDetail; 

    public CustomExpandableListAdapter(Context context, List<String> expandableListTitle, 
             HashMap<String, List<String>> expandableListDetail) { 
     this.context = context; 
     this.expandableListTitle = expandableListTitle; 
     this.expandableListDetail = expandableListDetail; 
    } 

    @Override 
    public Object getChild(int listPosition, int expandedListPosition) { 
     return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)) 
       .get(expandedListPosition); 
    } 

    @Override 
    public long getChildId(int listPosition, int expandedListPosition) { 
     return expandedListPosition; 
    } 

    @Override 
    public View getChildView(int listPosition, final int expandedListPosition, 
          boolean isLastChild, View convertView, ViewGroup parent) { 
     final String expandedListText = (String) getChild(listPosition, expandedListPosition); 
     if (convertView == null) { 

      //--------------------------------------------- 
      LayoutInflater layoutInflater = (LayoutInflater) this.context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

      convertView = layoutInflater.inflate(R.layout.child_element, null); 
     } 
     TextView expandedListTextView = (TextView) convertView 
       .findViewById(R.id.textChild); 
     expandedListTextView.setText(expandedListText); 

     ImageView editViewBtn = (ImageView)convertView.findViewById(R.id.sExp_BtnEdit); 
     editViewBtn.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View view, MotionEvent motionEvent) { 

       // do stuff 

       return false; 
      } 
     }); 


     return convertView; 
    } 

    @Override 
    public int getChildrenCount(int listPosition) { 
     return this.expandableListDetail.get(this.expandableListTitle.get(listPosition)) 
       .size(); 
    } 

    @Override 
    public Object getGroup(int listPosition) { 
     return this.expandableListTitle.get(listPosition); 
    } 

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

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

    @Override 
    public View getGroupView(int listPosition, boolean isExpanded, 
          View convertView, ViewGroup parent) { 
     String listTitle = (String) getGroup(listPosition); 
     if (convertView == null) { 
      LayoutInflater layoutInflater = (LayoutInflater) this.context. 
        getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

      convertView = layoutInflater.inflate(R.layout.group_element, null); 
     } 
     TextView listTitleTextView = (TextView) convertView 
       .findViewById(R.id.textGroup); 
     listTitleTextView.setTypeface(null, Typeface.BOLD); 
     listTitleTextView.setText(listTitle); 
     ImageView addV = (ImageView)convertView.findViewById(R.id.sExp_BtnAdd); 
     addV.setVisibility(View.VISIBLE); 

     addV.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View view, MotionEvent motionEvent) { 

       // do stuff 

       return false; 
      } 
     }); 

     return convertView; 
    } 

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

    @Override 
    public boolean isChildSelectable(int listPosition, int expandedListPosition) { 
     return true; 
    } 
} 

Các giả tạo dữ liệu:

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 

public class ExpandableListDataPump { 
    public static HashMap<String, List<String>> getData() { 
     HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>(); 

     List<String> ego = new ArrayList<String>(); 
     ego.add("dream 1"); 
     ego.add("dream 2"); 
     ego.add("dream 3"); 
     ego.add("dream 4"); 
     ego.add("dream 5"); 

     List<String> personalities = new ArrayList<String>(); 
     personalities.add("dream 1"); 
     personalities.add("dream 2"); 
     personalities.add("dream 3"); 
     personalities.add("dream 4"); 

     List<String> places = new ArrayList<String>(); 
     places.add("dream 1"); 
     places.add("dream 2"); 
     places.add("dream 3"); 
     places.add("dream 4"); 
     places.add("dream 5"); 

     expandableListDetail.put("Form of the ego", ego); 
     expandableListDetail.put("Form of other personalities", personalities); 
     expandableListDetail.put("Place's form", places); 
     return expandableListDetail; 
    } 
} 

Các hoạt động chính:

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ExpandableListAdapter; 
import android.widget.ExpandableListView; 
import android.widget.Toast; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 

public class Main4Activity extends AppCompatActivity { 


    ExpandableListView expandableListView; 
    ExpandableListAdapter expandableListAdapter; 
    List<String> expandableListTitle; 
    HashMap<String, List<String>> expandableListDetail; 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     expandableListView = (ExpandableListView) findViewById(R.id.sExpList); 
     expandableListDetail = ExpandableListDataPump.getData(); 
     expandableListTitle = new ArrayList<>(expandableListDetail.keySet()); 
     expandableListAdapter = new CustomExpandableListAdapter(this, expandableListTitle, expandableListDetail); 
     expandableListView.setAdapter(expandableListAdapter); 
     expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { 

      @Override 
      public void onGroupExpand(int groupPosition) { 
       Toast.makeText(getApplicationContext(), 
         expandableListTitle.get(groupPosition) + " List Expanded.", 
         Toast.LENGTH_SHORT).show(); 
      } 
     }); 

     expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() { 

      @Override 
      public void onGroupCollapse(int groupPosition) { 
       Toast.makeText(getApplicationContext(), 
         expandableListTitle.get(groupPosition) + " List Collapsed.", 
         Toast.LENGTH_SHORT).show(); 

      } 
     }); 

     expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 
      @Override 
      public boolean onChildClick(ExpandableListView parent, View v, 
             int groupPosition, int childPosition, long id) { 
       Toast.makeText(
         getApplicationContext(), 
         expandableListTitle.get(groupPosition) 
           + " -> " 
           + expandableListDetail.get(
           expandableListTitle.get(groupPosition)).get(
           childPosition), Toast.LENGTH_SHORT 
       ).show(); 
       return false; 
      } 
     }); 
    } 
} 

xml chính hơi thay đổi của bạn, đừng quên để chuyển đổi từ ImageButton để ImageView: (Tôi đã thay đổi một số các nguồn lực và kích thước mà bạn không share)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="10dp"> 


    <ExpandableListView 
     android:id="@+id/sExpList" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:groupIndicator="@null" /> 

    <!-- FOR PORTRAIT LAYOUTS !--> 
    <FrameLayout 
     android:id="@+id/adLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center_horizontal" 
     android:layout_marginTop="5dp" 
     android:baselineAligned="false" 
     android:orientation="vertical"/> 
</LinearLayout> 

Nhóm xml:

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

    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    > 

    <TextView 
     android:id="@+id/textGroup" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="17dp" 
     android:layout_marginTop="2dp" 
     android:layout_weight="7" 
     android:textStyle="bold" 
     android:textSize="13sp" /> 

    <ImageView 

     android:id="@+id/sExp_BtnAdd" 
     android:layout_width="25dp" 
     android:layout_height="25dp" 
     android:layout_gravity="center_vertical" 
     android:contentDescription="" 
     android:focusable="false" 
     android:scaleType="centerCrop" 
     android:src="@android:drawable/ic_input_add" /> 

</LinearLayout> 

con xml:

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

    <TextView 
     android:id="@+id/textChild" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
     android:layout_marginTop="2dp" 
     android:textColor="@android:color/white" 
     android:layout_weight="1" 
     android:textSize="13sp" /> 

    <ImageView 
     android:layout_width="20dp" 
     android:layout_height="20dp" 
     android:layout_marginEnd="?android:attr/expandableListPreferredItemPaddingLeft" 
     android:id="@+id/sExp_BtnEdit" 
     android:layout_gravity="center_vertical" 
     android:src="@android:drawable/ic_menu_edit" 
     android:scaleType="centerCrop" 
     android:focusable="false" 
     android:layout_marginRight="5dp" /> 

</LinearLayout> 

Uff ... đây là một cái dài, hy vọng nó sẽ giúp!

+0

Cảm ơn bạn đã cố gắng giúp tôi, tôi đã làm những gì bạn đề xuất - thay thế Nút có lượt xem và đã thêm sự kiện trênTouch, nhưng tiếc là kết quả của tôi không thay đổi. Tôi đã thêm mã hoạt động của mình, vui lòng xem lại mã đó có thể bạn sẽ tìm thấy điều gì đó sai ở đó. –

+0

Mặc dù bạn không trả lời bình luận của tôi, câu trả lời của bạn cho thấy rằng bạn đã thử một cách thực tế cho vấn đề này và mô phỏng nó để tìm hiểu những gì đang diễn ra, và mặc dù nó không giúp tôi (xem câu trả lời được chấp nhận), tôi quyết định để cung cấp cho bạn tiền thưởng :) –

+0

Cảm ơn bạn @ movsar đó là rất loại bạn. Bạn hoàn toàn đúng, xin lỗi vì đã không quay lại với bạn. Sau khi đọc câu trả lời được chấp nhận, tôi cũng không biết tại sao vấn đề là nền tảng, nhưng tôi không thể tái tạo cùng một vấn đề chính xác mà bạn có, thức ăn cho sự suy nghĩ? Một lần nữa cảm ơn! – HenriqueMS

0

Bạn đã cố gắng thiết lập gốc bố trí params của bạn trong cả hai danh sách các mục từ

android:layout_height="match_parent" 

để

android:layout_height="wrap_content" 

?

0

Android được thiết kế cho nhiều màn hình, vì vậy đôi khi một tệp bố cục duy nhất không thể hỗ trợ một số màn hình tốt. Một gợi ý có thể giúp bạn:

thực hiện một số điều chỉnh trong hồ sơ bố trí các hạng mục ban đầu, làm cho nó trên máy tính bảng phải, sau đó lưu và đặt các tập tin đã được điều chỉnh trong thư mục tương ứng như sau:

res/layout/my_layout.xml    // layout for normal screen size ("default") 
res/layout-large/my_layout.xml  // layout for large screen size 
res/layout-xlarge/my_layout.xml  // layout for extra-large screen size 
res/layout-xlarge-land/my_layout.xml // layout for extra-large in landscape orientation 

Và màn hình xlarge tối thiểu là 960dp x 720dp, màn hình lớn có ít nhất 640dp x 480dp, màn hình bình thường tối thiểu 470dp x 320dp, màn hình nhỏ ít nhất 426dp x 320dp.

văn bản chính thức về vấn đề này ở đây, https://developer.android.com/guide/practices/screens_support.html#qualifiers

Mà tôi nghĩ là một giải pháp tốt hơn để đối phó với hành vi bất thường trên bố trí bình thường.

Các vấn đề liên quan