4

データベースにいくつかの評価を保存しています.シークバーを移動すると、それらの評価がテキストビューに表示されます.しかし、問題は、親指を後ろに移動するたびに、後方の値が表示されないことです.最後の値のみが表示されます.評価を表示するにはどうすればよいですか親指を後方に動かしたとき。私が試したコードは -

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
    {
        view = inflater.inflate(R.layout.interval, container, false);
        seekbar=(SeekBar)view.findViewById(R.id.seekBar1);
        ques = (TextView)view. findViewById(R.id.question);
        textrating=(TextView)view.findViewById(R.id.textRating);
        /*l1=(LinearLayout)view.findViewById(R.id.linear);*/
        db=new DatabaseHandler(getActivity());
        retrieveQuestion();
        retrieveRating();
        seekbar.setProgress(0);
        seekbar.incrementProgressBy(diff);
        seekbar.setMax(ratinglast);

        seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
        {

            @Override
            public void onProgressChanged(SeekBar seekbar, int progress, boolean fromuser) 
            {
                 Log.e("DEBUG", "Progress is: "+progress);
                 if(j<len)
                 {
                     progress=rating[j];
                     j++;
                     textrating.setText(""+progress);
                 }




            }

            @Override
            public void onStartTrackingTouch(SeekBar seekbar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekbar) 
            {
                // TODO Auto-generated method stub


        }

        });


         return view;
    }

    void retrieveQuestion()
    {
        db.open();
        Cursor c=db.getQuestion(username,surveyName,selectedQues,question_no);
        if(c.moveToFirst())
        {
            int index=c.getColumnIndex("question");
            question1= c.getString(index);
            ques.setText(question1);
        }

    }

    public void retrieveRating()
    {
        Cursor c=db.getAnswer(username, surveyName, selectedQues, question_no);
        len=c.getCount();
        Log.e("len",""+len);
        if(c.moveToFirst())
        {
            do
            {
                int index=c.getColumnIndex("answer");
                rating[i]=c.getInt(index);
                Log.e("i",""+i);
                Log.e("rating in do while",""+rating[i]);
                i++;
            }while(c.moveToNext());
        }
        rating1=rating[0];
        rating2=rating[1];
        diff=rating2-rating1;
        Log.e("diff",""+diff);
        ratinglast=rating[len-1];
        Log.e("ratinglast",""+ratinglast);
    }
} 
4

1 に答える 1

1

私の問題に対する別の解決策を見つけました-

私が実装したコードは次のとおりです。

 public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
                {
                    view = inflater.inflate(R.layout.interval, container, false);
                    seekbar=(SeekBar)view.findViewById(R.id.seekBar1);
                    ques = (TextView)view. findViewById(R.id.question);
                    textrating=(TextView)view.findViewById(R.id.textRating);
                    db=new DatabaseHandler(getActivity());
                    retrieveQuestion();
                    retrieveRating();
                    seekbar.setProgress(0);
                    //ratinglast is last rating
                    seekbar.setMax(ratinglast);

                    seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
                    {

                        @Override
                        public void onProgressChanged(SeekBar seekbar, int progress, boolean fromuser) 
                        {
                             Log.e("DEBUG", "Progress is: "+progress);
                            //diff is difference between two ratings.
                             progress = ((int)Math.round(progress/diff ))*diff;
                             seekbar.setProgress(progress);
                             textrating.setText(progress + "");
            }
            @Override
                        public void onStartTrackingTouch(SeekBar seekbar) {
                            // TODO Auto-generated method stub
                        }

                        @Override
                        public void onStopTrackingTouch(SeekBar seekbar) 
                        {

                        }
                    });
                    return view;
                }
        //Method to retrieve rating from sqlite database
        public void retrieveRating()
            {
                Cursor c=db.getAnswer(username, surveyName, selectedQues, question_no);
                len=c.getCount();
                Log.e("len",""+len);
                if(c.moveToFirst())
                {
                    do
                    {
                        int index=c.getColumnIndex("answer");
                        rating[i]=c.getInt(index);
                        Log.e("i",""+i);
                        Log.e("rating in do while",""+rating[i]);
                        i++;
                    }while(c.moveToNext());
                }
                rating1=rating[0];
                rating2=rating[1];
                diff=rating2-rating1;
                Log.e("diff",""+diff);
                ratinglast=rating[len-1];
                Log.e("ratinglast",""+ratinglast);
            }
于 2014-03-27T06:52:33.633 に答える