显示先前的搜索栏值

时间:2014-03-26 06:06:24

标签: android android-seekbar

我在数据库中存储了一些评级。无论何时移动搜索栏,那么这些评级都会显示在textview中。但问题是每当我向后移动拇指时,都不显示向后的值。它只显示最后一个值。如何当我向后移动拇指时,我显示评级。我尝试过的代码是 -

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

1 个答案:

答案 0 :(得分: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);
            }