2012-02-28 3 views
0

안녕하세요 저는 헬프 활동을 디자인했고 각각의 특정 하위 항목이있는 종류의 부모 (groupItems)가 있습니다. 지금까지 문제가 없습니다. 그러나 ExpandableListView의 childItem은 기본적으로 클릭 할 수 있으므로 클릭하면 해당 항목이 깜박입니다. 그리고 정확히 내가 피하고 싶습니다! 내가하고 싶은 것을ExpandableListActivity childItems unclickable 만들기

public class HelpActivity extends ExpandableListActivity { 
private static final String TAG = "HelpActivity"; 

private static final String PARENT = "parent"; 
private static final String CHILD = "child"; 

private List<HashMap<String,String>> parents; 
private List<List<HashMap<String, String>>> childs; 

public void onCreate(Bundle savedInstanceState) { 
    Log.i(TAG, "Instantiated new " + this.getClass()); 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.help); 
    parents = createParentList(); 
    childs = createChildList(); 
    SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
     this, 
     parents,      // Describing data of group List 
     R.layout.help_group_item,  // Group item layout XML. 
     new String[] {PARENT},   // the key of group item. 
     new int[] {R.id.row_name},  // ID of each group item.-Data under the key goes into this TextView. 
     childs,       // childData describes second-level entries. 
     R.layout.help_child_item,  // Layout for sub-level entries(second level). 
     new String[] {CHILD},   // Keys in childData maps to display. 
     new int[] {R.id.grp_child}  // Data under the keys above go into these TextViews. 
    ); 
    setListAdapter(expListAdapter);  // setting the adapter in the list. 
} 

/* Creating the Hashmap for the row */ 
private List<HashMap<String,String>> createParentList() { 
    ArrayList<HashMap<String,String>> result = new ArrayList<HashMap<String,String>>(); 
    HashMap<String,String> m = new HashMap<String,String>(); 
    m.put(PARENT,getResources().getString(R.string.help_parent_1)); 
    result.add(m); 
    m = new HashMap<String,String>(); 
    m.put(PARENT,getResources().getString(R.string.help_parent_2)); 
    result.add(m); 
    m = new HashMap<String,String>(); 
    m.put(PARENT,getResources().getString(R.string.help_parent_3)); 
    result.add(m); 
    return result; 
} 

/* creatin the HashMap for the children */ 
private List<List<HashMap<String, String>>> createChildList() { 
    ArrayList<List<HashMap<String, String>>> result = new ArrayList<List<HashMap<String, String>>>(); 
    for (int i=0;i<parents.size();i++){ 
     HashMap<String, String> sec = parents.get(i); 
     ArrayList<HashMap<String, String>> secChild = new ArrayList<HashMap<String, String>>(); 
     HashMap<String,String> child = new HashMap<String,String>(); 
     if(sec.containsValue(getResources().getString(R.string.help_parent_1))){ 
      child.put(CHILD, getResources().getString(R.string.help_child_1)); 
     }else if(sec.containsValue(getResources().getString(R.string.help_parent_2))){ 
      child.put(CHILD, getResources().getString(R.string.help_child_2)); 
     }else if(sec.containsValue(getResources().getString(R.string.help_parent_3))){ 
      child.put(CHILD, getResources().getString(R.string.help_child_3)); 
     }else if(sec.containsValue(getResources().getString(R.string.help_parent_4))){ 
      child.put(CHILD, getResources().getString(R.string.help_child_4)); 
     } 
     secChild.add(child); 
     result.add(secChild); 
    } 
    return result; 
} 

}

이 여기

<?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="wrap_content"> 

    <TextView android:id="@+id/grp_child" 
     android:paddingLeft="20dp" 
     android:textSize="15dp" 
     android:textStyle="normal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

콘텐츠로 채워집니다 모든 (이 작동) 어떻게 내 소스 코드 내가 차일에 사용하는 레이아웃입니다 Textview를 자식보기를 취소 할 수 없도록 만드는 것입니다. 이미 텍스트 뷰 속성을 시도했지만 아무도 영향을받지 않았습니다.

android:clickable="false" 
android:focusable="false" 
android:enabled="false" 

아이디어를 가지고있는 사람에게 미리 감사드립니다!

답변

1

예를 들어 SimpleExpandableListAdapter를 확장하여 고유 한 ExpandableListAdapter를 사용자 정의하고 .newChildView() 및 .getChildView() 메소드를 재정의해야합니다. 재정의 된 메서드에서 하위 뷰의 OnClickListener 및 OnLongClickListener를 모두 null로 설정하여 사용자 정의 할 수 있습니다.

@Override 
public View newChildView(boolean isLastChild, ViewGroup parent) { 
    View v = super.newChildView(isLastChild, parent); 
    v.setOnClickListener(null); 
    v.setOnLongClickListener(null); 
    return v; 
} 

@Override 
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent); 
    v.setOnClickListener(null); 
    v.setOnLongClickListener(null); 
    return v; 
} 

전망의 클릭 가능한 속성은이 상태 '를 누르면'로 변경됩니다인지 여부를 결정 클릭하면, 그것은보기를 클릭 여부를받을 수 있는지 여부에 중요한 역할을하지 않습니다. 당신이 어떤 "반응"클릭에, 초점 등

+0

좋아요, 나는 이미 나오지 않았어 생각 그렇게 어려운 일이 아닙니다. 그냥 시도해 보았습니다. 완벽하게 작동합니다. 고맙습니다. – Vossi

1

을 제거하기 위해 제거해야 있도록 ExpandableListAdapter, 그 그룹과 아이 뷰에 기본 리스너를 설정하십시오이 :

getExpandableListView().setOnChildClickListener(null); 
+0

해결책도 확인했지만 제대로 작동하지 않습니다. 어쨌든 답장을 보내 주셔서 감사합니다. – Vossi

관련 문제