Android 如何禁用onTouch()?
当我的LoadPreview().execute启动时,我试图禁用onTouch(),因为如果用户点击触发我的LoadPreview()的按钮,将会有重复的预览按钮。因此,我想在加载过程中禁用onTouch() 有办法吗 这是我的ontouch方法:Android 如何禁用onTouch()?,android,android-view,touch-event,Android,Android View,Touch Event,当我的LoadPreview().execute启动时,我试图禁用onTouch(),因为如果用户点击触发我的LoadPreview()的按钮,将会有重复的预览按钮。因此,我想在加载过程中禁用onTouch() 有办法吗 这是我的ontouch方法: @Override public boolean onTouch(View arg0, MotionEvent arg1) { // TODO Auto-generated m
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
switch(arg1.getAction())
{
case MotionEvent.ACTION_DOWN:
adapter.clear();
new LoadPreview().execute();
break;
}
return true;
}
}
);
}
这是我的loadpreview()
/**
*通过发出HTTP请求加载所有产品的后台异步任务
* */
类LoadPreview扩展了异步任务{
/**
*获取预览url,然后加载它们
* */
受保护的字符串doInBackground(字符串…args){
//建筑参数
List params=new ArrayList();
//从URL获取JSON字符串
JSONObject json=jParser.makeHttpRequest(url_杂志,“GET”,参数);
//检查日志cat中的JSON响应
Log.d(“所有产品:,json.toString());
试一试{
//检查成功标签
int success=json.getInt(TAG_success);
如果(成功==1){
//发现的产品
//获取一系列产品
mag=json.getJSONArray(TAG_杂志);
对于(int i=0;i 对于(int a=0;a使用标志。在类中放入布尔allowTouch。默认为true。当您要停止触摸时,将其设置为false。当您准备再次进行触摸时,将其设置为true。更改onTouch方法,使其仅在allowTouch==true时运行其中的代码。使用标志。在类中放入布尔allowTouch。默认值为true。当您要停止触摸时,将其设置为false。当您准备再次进行触摸时,将其设置为true。更改onTouch方法,使其仅在allowTouch==true时运行其中的代码。使用布尔
标志检查是否正在加载数据以防止重复调用
声明一个全局布尔值
,例如:布尔值加载数据;
然后,在onTouch()
方法中,设置loadingPreview=true;
最后,在AsyncTask的loadingPreview
方法中,将loadingPreview
切换为loadingPreview=false;
这将确保在提取数据时不会创建重复类。切换状态将确保应用程序再次准备就绪
编辑:在调用AyncTaskloadingPreview
if (loadingPreview == false) {
new LoadPreview().execute();
}
使用布尔
标志检查是否正在加载数据以防止重复调用
声明一个全局布尔值
,例如:布尔值加载数据;
然后,在onTouch()
方法中,设置loadingPreview=true;
最后,在AsyncTask的loadingPreview
方法中,将loadingPreview
切换为loadingPreview=false;
这将确保在提取数据时不会创建重复类。切换状态将确保应用程序再次准备就绪
编辑:在调用AyncTaskloadingPreview
if (loadingPreview == false) {
new LoadPreview().execute();
}
照加布说的做。
你也可以做我刚才解释过的事情。
1.定义一个布尔值,如:
private boolean process = false;
在AsyncTask中重写类似onPreExecution的方法
将布尔值放在上述方法上,并将其值定义为true
过程=真
现在,onPostExecution方法将以下内容放入:
过程=假
并实现如下所示的onTouch方法:
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
if(process==false){
switch(arg1.getAction())
{
case MotionEvent.ACTION_DOWN:
adapter.clear();
new LoadPreview().execute();
break;
}
return true;
}
else{
return false;
}
}
))
**对于Ontinclick**
您可以使用下面的代码使onItemClick按您的需要工作
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if(process==false)
{
adapter.clear();
File sdCard1 = Environment.getExternalStorageDirectory();
File dir1 = new File (sdCard1.getAbsolutePath() + "/Futsing/issue"+issueNumber+"/");
/** IF FILE EXISTS **/
if(dir1.exists())
{
Intent intent = new Intent();
intent.setClass(CoverFlowExample.this, Reader.class);
intent.putExtra("issue", issueNumber);
startActivityForResult(intent, GET_INTENT_CODE);
}
else
{
new LoadPreview().execute();
}
}else{
// nothing to do here it means the process is running
}
}
}
@覆盖
公共链接(AdapterView arg0、视图arg1、,
整数arg2,长arg3){
if(进程==false)
{
适配器。清除();
文件sdCard1=Environment.getExternalStorageDirectory();
File dir1=新文件(sdCard1.getAbsolutePath()+“/Futsing/issue”+issueNumber+“/”;
/**如果文件存在**/
if(dir1.exists())
{
意图=新意图();
setClass(CoverFlowExample.this,Reader.class);
意向。额外支付(“发行”,发行人);
startActivityForResult(意图,获取意图代码);
}
其他的
{
新建LoadPreview().execute();
}
}否则{
//此处无需执行任何操作,表示进程正在运行
}
}
}
照加布说的做。
你也可以做我刚才解释过的事情。
1.定义一个布尔值,如:
private boolean process = false;
在AsyncTask中重写类似onPreExecution的方法
将布尔值放在上述方法上,并将其值定义为true
过程=真
现在,onPostExecution方法将以下内容放入:
过程=假
并实现如下所示的onTouch方法:
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
if(process==false){
switch(arg1.getAction())
{
case MotionEvent.ACTION_DOWN:
adapter.clear();
new LoadPreview().execute();
break;
}
return true;
}
else{
return false;
}
}
))
**对于Ontinclick**
您可以使用下面的代码使onItemClick按您的需要工作
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if(process==false)
{
adapter.clear();
File sdCard1 = Environment.getExternalStorageDirectory();
File dir1 = new File (sdCard1.getAbsolutePath() + "/Futsing/issue"+issueNumber+"/");
/** IF FILE EXISTS **/
if(dir1.exists())
{
Intent intent = new Intent();
intent.setClass(CoverFlowExample.this, Reader.class);
intent.putExtra("issue", issueNumber);
startActivityForResult(intent, GET_INTENT_CODE);
}
else
{
new LoadPreview().execute();
}
}else{
// nothing to do here it means the process is running
}
}
}
@覆盖
公共空间