1

私はsqliteから表示されたグリッドビューにアイテムを持っています..今、別のスレッドを使用して、json Webサービスからデータをフェッチし、データをsqliteに保存しています。既存のアイテムと一緒に更新されたアイテムを同じグリッドビューに表示したい. .

  private void displayUpdate(String Bid) {

             Log.w("Update cALL","Executing Update");
            System.out.println("aeqw cursor that in display table value"+getid(Bid).getCount());
            Cursor cursorx =getid(Bid);

            int p=Integer.parseInt(Bid);
            System.err.println("Recieving Bid to displayUpdate method"+p);
            if (getid(Bid) != null)
            {
                while(cursorx.moveToFirst())
                {

                    Log.e("Entering Loop", "WHILE EXECUTING");
                    String temp_id1 = cursorx.getString(0);
                    System.err.println("Name related to Bid to displayUpdate method"+temp_id1);
                    final String temp_name1 = cursorx.getString(1);
                    System.err.println("Name related to Bid to displayUpdate method"+temp_name1);
                    String temp_author1=cursorx.getString(2);
                    String temp_desc1=cursorx.getString(3);
                    byte[] temp_image1 = cursorx.getBlob(4);
                    String temp_rating1 = cursorx.getString(5);
                    String temp_price1 = cursorx.getString(6);
                    String temp_update1=cursorx.getString(7);
                    System.err.println("Name related to Bid to displayUpdate method"+temp_name1);
                    mapIdUp.add(temp_id1);
                    mapNameUp.add(temp_name1);
                    mapAuthorUp.add(temp_author1);
                    mapDescUp.add(temp_desc1);
                    mapRatingUp.add(temp_rating1);
                    mapPriceUp.add(temp_price1);
                    mapUp.add(temp_image1);
                    mapUpdatedUp.add(temp_update1);
                        Log.e("temp_id from the sqlite", temp_id1);
                        Log.i(temp_name1, temp_name1);
                        Log.i(temp_desc1, temp_desc1);
                        Log.i(temp_rating1, temp_rating1);
                        Log.e(temp_update1,temp_update1);
                        String[] captionArray1 = (String[]) mapNameUp.toArray(new String[mapNameUp.size()]);
                    ItemsAdapter itemsAdapter1 = new ItemsAdapter(
                            Bookicon.this, R.layout.item,captionArray1);

                    gridView1=(GridView)findViewById(R.id.list);
                    gridView1.setAdapter(itemsAdapter1);
                    itemsAdapter1.notifyDataSetChanged();
                    gridView1.setOnItemClickListener(new OnItemClickListener() {
                        public void onItemClick(AdapterView<?> parent, View v, int position, long id)
                        {
                            Intent i = new Intent(getApplicationContext(), DetailsActivity.class);

                            i.putExtra("id", position);

                            startActivity(i);
                        }
                    });
                    break;
                }       
            }   

            }

このメソッドは、更新された書籍を表示するために 2 番目のスレッドで呼び出されます。

このメソッドは、sqlite テーブルのすべてのアイテムを表示するために使用されます。

     private void getDataAndPopulate() 
    {

         Log.w("hello","zyuk,");

        Cursor cursor = getEvents("bcuk_book");

        while (cursor.moveToNext())
        {
             String temp_id = cursor.getString(0);
             final String temp_name = cursor.getString(1);
             String temp_author=cursor.getString(2);
             String temp_desc=cursor.getString(3);
             byte[] temp_image = cursor.getBlob(4);
             String temp_rating = cursor.getString(5);
             String temp_price = cursor.getString(6);
             String temp_update=cursor.getString(7);
             mapId.add(temp_id);
             mapName.add(temp_name);
             mapAuthor.add(temp_author);
             mapDesc.add(temp_desc);
             mapRating.add(temp_rating);
             mapPrice.add(temp_price);
             map.add(temp_image);
             mapUpdated.add(temp_update);
                Log.e("temp_id from the sqlite", temp_id);
                Log.i(temp_name, temp_name);
                Log.i(temp_desc, temp_desc);
                Log.i(temp_rating, temp_rating);
                Log.e(temp_update,temp_update);
                String[] captionArray = (String[]) mapName.toArray(new String[mapName.size()]);
                ItemsAdapter itemsAdapter = new ItemsAdapter(
                        Bookicon.this, R.layout.item,captionArray);
                gridView=(GridView)findViewById(R.id.list);
                gridView.setAdapter(itemsAdapter);
                gridView.setOnItemClickListener(new OnItemClickListener() {
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id)
                    {

                        Intent i = new Intent(getApplicationContext(), DetailsActivity.class);

                        i.putExtra("id", position);

                        startActivity(i);
                    }
                });

        }   
        }

問題は、既に保存されているアイテムを表示していたのに、更新されたものを表示できないことです..

新しいアイテムを 6 で更新すると 1,2,3,4,5 のようなアイテムがあると仮定すると、最初のアイテム、つまり 1 のレコードが表示されます。2 つのレコードを更新すると、最初の 2 つのレコードのみが表示されます。

この問題を解決する方法

4

0 に答える 0