gpt4 book ai didi

android - 我如何禁用 onTouch()?

转载 作者:行者123 更新时间:2023-11-30 03:49:28 26 4
gpt4 key购买 nike

我试图在我的 LoadPreview().execute 启动时禁用 onTouch(),因为如果用户点击触发我的 LoadPreview() 的按钮,将会出现重复的预览按钮。所以我想在加载过程中禁用 onTouch()。

有办法吗?

这是我的ontouch方法:

@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()

/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadPreview extends AsyncTask<String, String, String> {

/**
* getting preview url and then load them
* */
protected String doInBackground(String... args) {


// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_magazine, "GET", params);

// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());

try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);

if (success == 1) {
// products found
// Getting Array of Products
mag = json.getJSONArray(TAG_MAGAZINE);

for (int i = 0; i < mag.length(); i++) {
JSONObject c = mag.getJSONObject(i);

// Storing each json item in variable
String magazinePreview = c.getString(TAG_MAGAZINE_PREVIEW);

previewList.add(magazinePreview);
}
}
else {

}
} catch (JSONException e) {
e.printStackTrace();
}

for (int a = 0; a <= previewList.size(); a++)
{
if(pos == a)
{
// Building Parameters
List<NameValuePair> param = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json1 = jParser.makeHttpRequest(previewList.get(a), "GET", param);

// CHECKING OF JSON RESPONSE
Log.d("All guide: ", json.toString());

try {
preview = json1.getJSONArray(TAG_PREVIEWS);

for (int i = 0; i < preview.length(); i++) {
JSONObject c = preview.getJSONObject(i);

String image = c.getString(TAG_IMAGE);

previewImagesList.add(image);
//System.out.println(guideList);
}

// STOP THE LOOP
break;

} catch (JSONException e) {
e.printStackTrace();
}


}

}


return null;
}

/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {

/**
* Updating parsed JSON data into ListView
* */
adapter.notifyDataSetChanged();

}
}

onItemClick 方法:

coverFlow.setOnItemClickListener(new OnItemClickListener()
{

@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {

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
{
if(process==false)
{
new LoadPreview().execute();
process = true;
}

else
{
process = false;
}
}
}

}

);

最佳答案

按照Gabe说的去做。你也可以像我在这里解释的那样做。1. 定义一个 bool 值:

private boolean process = false;
  1. 重写AsyncTask中的onPreExecution等方法。
  2. 将 bool 值放在上述方法上并将其值定义为 true。

    process = true;

  3. 现在,onPostExecution 方法把这个:

    进程=假

  4. 并像下面这样实现您的 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;
    }

    }

    );

** 对于 onItenClick **

您可以使用下面的代码让 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
}
}

}

关于android - 我如何禁用 onTouch()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14391969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com