English 中文(简体)
Anders set new Curor to a list
原标题:Android set new Cursor to a listView

我在环境中对新的<代码>Adapter至没有什么问题。 用户在<代码>EditText上签字时查阅。 因此,当我的<条码>活性

问题在于,当我开始打字时,我可以从LogCat的Logs那里看到, s状是正确的,是曲线的大小,但我的意见清单充满了新的数据。 它维持不变。 在这里,我怎么做:

这是我首次提出该名单:

cursor = userDbHelper.executeSQLQuery(sqlQuery);

        if (cursor.getCount() == 0) {
            noCards.setVisibility(View.VISIBLE);
            noCards.setText(getString(R.string.no_cards));
        } else if (cursor.getCount() > 0) {
            noCards.setVisibility(View.GONE);
                for (cursor.move(0); cursor.moveToNext(); cursor.isAfterLast()) {
                    objectId = Integer.parseInt(cursor.getString(cursor.getColumnIndex("objectId")));
                    cardId.add(objectId);

                    title = cursor.getString(cursor.getColumnIndex("title"));
                    catTitle = cursor.getString(cursor.getColumnIndex("catTitle"));
                    int repeats = Integer.parseInt(cursor.getString(cursor.getColumnIndex("repeatsCount")));
                    count.add(repeats);

                    if(extra != 0){
                                String cardsm = "SELECT objectId FROM cardmedias "
                                                + "WHERE cardId="
                                                + objectId
                                                + " AND mediaType=" 
                                                + 5012;

                                Cursor cardsM = userDbHelper.executeSQLQuery(cardsm);
                                if (cardsM.getCount() == 0) {


                                } else if (cardsM.getCount() > 0) {
                                    for (cardsM.move(0); cardsM.moveToNext(); cardsM.isAfterLast()) {
                                        objectID = Integer.parseInt(cardsM.getString(cardsM.getColumnIndex("objectId")));

                                        String filename = "mediacard-"+objectID;
                                        if(storageID==1){
                                            path = RPCCommunicator.getImagePathFromInternalStorage(servername, userId, filename, this);
                                        } else if(storageID==2){
                                            path = RPCCommunicator.getImagePathFromExternalStorage(servername, userId, filename);
                                        }
                                        hm.put(objectID, path);

                                        path = hm.get(objectID);
                                        Log.i("","path : "+path);
                                        paths.add(path);
                                        names.add(title);
                                        categories.add(catTitle);
                                    }
                                }
                    } else if (extra==0){
                        names.add(title);
                        categories.add(catTitle);
                    }
                }
        }
        cursor.close();
        adapter = new LazyAdapter(this, paths, names, categories, count);
        listView.setAdapter(adapter);

而这正是创建新教程和适应器时如何。

searchString = "";
    sqlQuery = getSqlQuery(sort, collId, ascDesc,searchString);

    searchBar.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        public void afterTextChanged(Editable s) {
            check = 1;
            listView.setAdapter(null);
            searchString = s.toString();
            Log.e("","searchString : "+searchString);
            sqlQuery = getSqlQuery(sort, collId, ascDesc,searchString);
            Log.e(""," sqlquery : "+sqlQuery);
            Cursor cursor = userDbHelper.executeSQLQuery(sqlQuery);
            Log.e("","cursor count : "+cursor.getCount());
            if (cursor.getCount() == 0) {
                noCards.setVisibility(View.VISIBLE);
                noCards.setText(getString(R.string.no_cards));
            } else if (cursor.getCount() > 0) {
                noCards.setVisibility(View.GONE);
                    for (cursor.move(0); cursor.moveToNext(); cursor.isAfterLast()) {
                        objectId = Integer.parseInt(cursor.getString(cursor.getColumnIndex("objectId")));
                        cardId.add(objectId);

                        title = cursor.getString(cursor.getColumnIndex("title"));
                        catTitle = cursor.getString(cursor.getColumnIndex("catTitle"));
                        int repeats = Integer.parseInt(cursor.getString(cursor.getColumnIndex("repeatsCount")));
                        count.add(repeats);

                        if(extra != 0){
                                    String cardsm = "SELECT objectId FROM cardmedias "
                                                    + "WHERE cardId="
                                                    + objectId
                                                    + " AND mediaType=" 
                                                    + 5012;

                                    Cursor cardsM = userDbHelper.executeSQLQuery(cardsm);
                                    if (cardsM.getCount() == 0) {

                                    } else if (cardsM.getCount() > 0) {
                                        for (cardsM.move(0); cardsM.moveToNext(); cardsM.isAfterLast()) {
                                            objectID = Integer.parseInt(cardsM.getString(cardsM.getColumnIndex("objectId")));

                                            String filename = "mediacard-"+objectID;
                                            if(storageID==1){
                                                path = RPCCommunicator.getImagePathFromInternalStorage(servername, userId, filename, OwnedStampii.this);
                                            } else if(storageID==2){
                                                path = RPCCommunicator.getImagePathFromExternalStorage(servername, userId, filename);
                                            }
                                            hm.put(objectID, path);

                                            path = hm.get(objectID);
                                            Log.i("","path : "+path);
                                            paths.add(path);
                                            names.add(title);
                                            categories.add(catTitle);
                                        }
                                    }
                        } else if (extra==0){
                            names.add(title);
                            categories.add(catTitle);
                        }
                    }
            }
            cursor.close();

            LazyAdapter adapter = new LazyAdapter(OwnedStampii.this, paths, names, categories, count);
            listView.setAdapter(adapter);

        }
    });

So any ideas how can I refresh my list View with the new adapter. I ve already tried with adapter.notifySetDataChanged(); and it s not working.

提前感谢!

最佳回答

我确定,在我的<编码>后,TextChanged()。 I m 只是通过储存数据并公布新的数据来清除阵列清单。

问题回答

clear your data sources in this case it is paths, names, categories, count. Load new results into data sources of list(paths, names, categories, count), and don s set list adapter to null, and call notifyDataSetChanged.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签