2010-03-03 1661 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语句中留下,因为你会在每次手势之后用数百条日志记录行向你发送垃圾邮件;他们只是为了明确发生了什么。