I am trying to disable onTouch() when my LoadPreview().execute is being launched because if the user taps on the button which triggles my LoadPreview(), there will be duplicate preview buttons. So I want to disable onTouch() during the loading process.
is there a way?
This is my ontouch method:
@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;
}
}
);
}
this is my 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 method:
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;
}
}
}
}
);
do as Gabe said.
You can also do the thing like here i have explained.
1. define one boolean like:
Put boolean on the above method an define its value to true.
process = true;
Now, onPostExecution method put this:
process = false
And also implement your onTouch method like below:
);
** FOR onItenClick **
You can use below code for onItemClick to work as you want.