Search code examples
androidsqlitecursorimageviewcursor-position

How to Set Next Image to ImageView from database after an Edit text Event?


I Have 1 image view and 4 Edit texts ,On runtime i am setting ImageView with first image from database, Then asking user to input text for image displayed if correct match found the ImageView gets updated and set to next Image from database,but next image is not getting set. PLZ can any one solve the problem ..?

while(true)
    {
        cur.move(counter);
        int p =cur.getPosition();
        Log.v("Cursor Position:",Integer.toString(p));
        byte[] image = cur.getBlob(cur.getColumnIndex("image"));
        Bitmap bmp=BitmapFactory.decodeByteArray(image, 0, image.length);
        countryName = cur.getString(cur.getColumnIndex("name"));
        countryImage.setImageBitmap(bmp);

        firstAns.setOnKeyListener(new OnKeyListener()
        {

            public boolean onKey(View v, int keyCode, KeyEvent event)
            {
                if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
                {

                    String fst = firstAns.getText().toString().trim();
                    check(fst);

                }    
                return false;
            }

            private boolean check(String fst) 
            {
                if(fst.equals(countryName))
                {
                    counter++;
                    Toast.makeText(CategoryEvent.this, "Ans Is Correct", 10).show();
                    return true;
                }
                else
                {
                    Toast.makeText(CategoryEvent.this, "Ans Is Not Correct", 10).show();
                    firstAns.clearFocus();
                    firstAns.setEnabled(false);
                    return false;
                    //firstAns.setNextFocusDownId(R.id.secondEdit);
                }
            }

        });
    }

Solution

  • You need to decode another bitmap from the database and call ImageView.setImageBitmap again. Moving cursor to a next item (cur.moveToNext()) is not enough.