I have a list view and when item in the listview clicked, I save the detail to sqlite db using AyscTask which is called from listview’s onitemclicklistener. When user randomly clicks many items application crashes as app try to access db in peculier way. This happens when the user is fast enough to click multiple items in the listview before the loading alert shows up.
How can I prevent this?? I tried to disable listview inside the listview’s onitemclick method but it didn’t work too.
my code
//setting up the listview
ListView lv = (ListView) findViewById(android.R.id.list);
setListAdapter(new TypeArrayAdapter(TypeSelectActivity.this, R.layout.row_type, typeList));
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
sectionid = Integer.parseInt(LocationWebService.incidentTypeSectionId
.get(arg2));
incidentid1 = Integer
.parseInt(LocationWebService.incidentTypeId
.get(arg2));
LocationWebService.IncidentTypeID = incidentid1;
LocationWebService.sectionID = sectionid;
new DBTasks().execute(arg2);
TextView tv=(TextView)arg1.findViewById(R.id.label_type);
TypeString=tv.getText().toString();
Log.v("TypeSelect", TypeString);
}
});
Thanks for your time in advance.
try using disable the list in AsnykTask ->
PreExecuteand enabling the list inPostExecute..