簡體   English   中英

Android:單擊后禁用ListView?

[英]Android: Disable ListView once clicked?

我有一個列表視圖,當單擊列表視圖中的項目時,我使用AyscTask將詳細信息保存到sqlite db,該方法是從列表視圖的onitemclicklistener調用的。 當用戶隨機單擊許多項目時,應用程序崩潰,因為應用程序嘗試以更特殊的方式訪問數據庫。 當用戶足夠快地在加載警報顯示之前單擊列表視圖中的多個項目時,就會發生這種情況。

我該如何預防呢? 我試圖在listview的onitemclick方法中禁用listview,但是它也沒有起作用。

我的代碼

//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);

            }
        });

謝謝您的時間。

嘗試在AsnykTask-> PreExecute使用禁用列表,並在PostExecute啟用列表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM