2010-06-06 98 views
6

我有一個相當複雜的ListView。每個項目看起來是這樣的:ListView項目不可點擊Horizo​​ntalScrollView裏面

> LinearLayout (vertical) 
    > LinearLayout (horizontal) 
    > include (horizontal LinearLayout with two TextViews) 
    > include (ditto) 
    > include (ditto) 
    > TextView 
    > HorizontalScrollView (this guy is my problem) 
    > LinearLayout (horizontal) 

在我的活動,一個項目被創建時(getView()叫)我添加動態TextView S到HorizontalScrollViewLinearLayout(除了填充其他更簡單的東西了)。令人驚訝的是,表現非常好。

我的問題是,當我添加HorizontalScrollView時,我的列表項變得無法點擊。點擊時他們不會獲得橙色背景,並且他們不會觸發我設置的OnItemClickedListener(執行簡單的Log.d調用)。

如何讓我的列表項再次點擊?


編輯:設置在最高LinearLayoutandroid:descendantFocusability="blocksDescendants"似乎工作。不過,我想知道是否還有其他方法:如果我想在我的列表項目中設置可聚焦的項目,該怎麼辦?

回答

8

在最上面的LinearLayout上使用android:descendantFocusability="blocksDescendants"做了訣竅。裏面的元素仍然可以「可點擊」,但它們只是不可聚焦(即,您無法在非觸摸屏設備上點擊它們)。對我來說足夠了。

0

當我申請Horizo​​ntalScrollView我TableLayout滾動工作正常,但無法點擊列表項 我的佈局爲follwos

的LinearLayout Horizo​​ntalScrollView TableLayout ......... /TableLayout /Horizo​​ntalScrollView /LinearLayout中

我施加機器人:descendantFocusability =「blocksDe 「我的最高線性佈局」任何幫助

0
android:descendantFocusability="blocksDescendants" 

沒有幫助我。 所以

所以,我意識到監聽模式。

public interface EventListItemOnClickListener { 
    public void itemClicked(); 
} 

而且在適配器通知所有偵聽

private List<EventListItemOnClickListener> listeners; 
protected void notifyOnClick(int position){ 
    for(int i=0; i<listeners.size();++i) 
    listeners.get(i).itemClicked((Event)events.get(position)); 
} 
... 
    @Override 
    public void onClick(View v) { 
     notifyOnClick(position); 
    } 
... 
相關問題