2010-03-03 1670 views
2

雖然顯示進度條我想禁用觸摸屏來限制android手機中的其他功能。如何在Android手機中禁用觸摸屏?

任何人都可以指導我如何實現這一目標?

任何幫助將被處理。

+1

這將採取控制遠離用戶和一個壞主意,所以我懷疑它可以完成,我不明白爲什麼有人會希望它完成 – 2010-03-03 10:50:43

+0

好吧,當我在列表中顯示進度時,我已經實現了點擊功能列表item.during進度條被激活,如果有一個按下列表項目。它需要控制一些其他活動,所以我想限制這一點。 – UMAR 2010-03-03 11:04:46

+1

只需從列表中刪除onClick功能? – 2010-03-03 11:32:41

回答

5

編輯

您可以通過實現ListView控件的自定義擴展已設爲列表中的XML文件中使用做到這一點。然後在你的CustomListView中,實現onTouchEvent方法,如果你想讓列表處理觸摸,只調用super.onTouchEvent。這就是我的意思:

在包含您的列表的佈局文件中有這種效果。

<com.steve.CustomListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/start_menu_background" 
    android:cacheColorHint="#00000000" 
    android:id="@android:id/list"> 
</com.steve.CustomListView> 

然後有一個自定義類這樣的:

public class CustomListView extends ListView { 
    Context mContext; 

    public CustomListView (Context context, AttributeSet attrs){ 
     super(context, attrs); 
     mContext = context; 
    } 

    public boolean onTouchEvent(MotionEvent event){ 
     if (event.getRawY() < 100){ 
      Log.d("Your tag", "Allowing the touch to go to the list."); 
      super.onTouchEvent(event); 
      return true; 
     } else { 
      Log.d("Your tag", "Not allowing the touch to go to the list."); 
      return true; 
     } 
    } 
} 

此代碼將只允許觸摸事件由ListView控件,如果他們在屏幕頂部100像素得到處理。很明顯,將if語句替換爲更適合您的應用程序的東西。一旦你使用Log語句,也不要在Log語句中留下,因爲你會在每次手勢之後用數百條日誌記錄行向你發送垃圾郵件;他們只是爲了明確發生了什麼。