0
這裏我試圖實現兩個評級欄ratingbar1和ratingbar2,但錯誤表示只能調用一個onRatingChanged,那麼我怎樣才能實現ratingbar2。如何在一個片段中實現兩個評級欄
雖然當我試圖只實施ratingbar1,我的代碼工作正常。
請告訴我如何實現ratingbar2的onRatingChanged方法?
public class FragmentT12 extends Fragment implements RatingBar.OnRatingBarChangeListener
{
View view;
TextView textbox1,textbox2;
RatingBar ratingbar1,ratingbar2;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view= inflater.inflate(R.layout.fragment_t12,container,false);
textbox1=(TextView)view.findViewById(R.id.textbox1);
textbox2=(TextView)view.findViewById(R.id.textbox2);
ratingbar1=(RatingBar)view.findViewById(R.id.ratingbar1);
ratingbar2=(RatingBar)view.findViewById(R.id.ratingbar2);
ratingbar1.setOnRatingBarChangeListener(this);
ratingbar2.setOnRatingBarChangeListener(this);
return view;
}
@Override
public void onRatingChanged(RatingBar ratingbar1, float rating, boolean fromUser)
{
float i;
i=ratingbar1.getRating();
if(i==1.0)
{textbox1.setText("Strongly Disagree");
textbox1.setTextColor(Color.parseColor("#990000"));
textbox1.setTypeface(Typeface.SERIF);
}
else if(i==2.0)
{textbox1.setText("Disagree");
textbox1.setTextColor(Color.parseColor("#996600"));
textbox1.setTypeface(Typeface.SERIF);}
else if(i==3.0)
{textbox1.setText("Neither Agree Nor Disagree");
textbox1.setTextColor(Color.parseColor("#006666"));
textbox1.setTypeface(Typeface.SERIF);}
else if(i==4.0)
{textbox1.setText("Agree");
textbox1.setTextColor(Color.parseColor("#0033cc"));
textbox1.setTypeface(Typeface.SERIF);}
else if(i==5.0)
{textbox1.setText("Strongly Agree");
textbox1.setTextColor(Color.parseColor("#009933"));
textbox1.setTypeface(Typeface.SERIF);}
}
public void onRatingChanged(RatingBar ratingbar2, float rating, boolean fromUser)**ERROR IS HERE
{
float i;
i=ratingbar2.getRating();
if(i==1.0)
{textbox2.setText("Strongly Disagree");
textbox2.setTextColor(Color.parseColor("#990000"));
textbox2.setTypeface(Typeface.SERIF);
}
else if(i==2.0)
{textbox2.setText("Disagree");
textbox2.setTextColor(Color.parseColor("#996600"));
textbox2.setTypeface(Typeface.SERIF);}
else if(i==3.0)
{textbox2.setText("Neither Agree Nor Disagree");
textbox2.setTextColor(Color.parseColor("#006666"));
textbox2.setTypeface(Typeface.SERIF);}
else if(i==4.0)
{textbox2.setText("Agree");
textbox2.setTextColor(Color.parseColor("#0033cc"));
textbox2.setTypeface(Typeface.SERIF);}
else if(i==5.0)
{textbox2.setText("Strongly Agree");
textbox2.setTextColor(Color.parseColor("#009933"));
textbox2.setTypeface(Typeface.SERIF);}
}
}
Thanks.It工作。 –