是否有关于android的ratingbars的指导方针?我正在开发一个Android应用程序和我开发它的方式,我只能通过将其添加到对话框来设置和编辑某些内容的评级。
我想知道是否有关于评级栏的指导方针 - 是否可以将其放在对话框中?或者我应该解决这个问题?
答案 0 :(得分:1)
RatingBar是SeekBar和ProgressBar的扩展,显示星级评分。使用默认大小RatingBar时,用户可以触摸/拖动或使用箭头键设置评级。较小的RatingBar样式(
ratingBarStyleSmall
)和较大的仅指示样式(ratingBarStyleIndicator
)不支持用户交互,只应用作指标。当使用支持用户交互的RatingBar时,不鼓励将小部件放在RatingBar的左侧或右侧。
当然支持可编辑的评分栏并且RatingBar
的有效使用 - Google Play商店就评分内容提供了一个很好的例子。
答案 1 :(得分:0)
我担心的是我的评级栏在适配器类中(如下所示)。我希望能够获得评级栏链接到的用户的位置。我能想到的唯一解决办法就是把它放在一个对话框中(这就是我提问的原因)。我通过使onRatingChanged
中的位置成为最终的getView
来解决我的问题(如何从一个内在的类中访问该位置)。阅读此处:Making paramters final关于最终属性。真的很有用。
适配器类
public class PersonAdapter extends ArrayAdapter<Person> {
private Context context;
private List<Person> people;
public PersonAdapter(Context context, List<Person> people) {
super(context, R.layout.person_layout, people);
this.context = context;
this.people = people;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
// if this is a new view, then inflate it
View personView = convertView;
if (personView == null)
{
// get the inflater that will convert the person_layout.xml file
// into an actual object (i.e. inflate it)
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// create a view to display the person's info
personView = inflater
.inflate(R.layout.person_layout, parent, false);
TextView txt1stTime = (TextView) personView
.findViewById(R.id.txt1stTime);
txt1stTime.setText("1st time");
}
else
{
TextView txt1stTime = (TextView) personView
.findViewById(R.id.txt1stTime);
txt1stTime.setText("Recycled");
}
// keep track of person this view is working with
personView.setTag(people.get(position));
// get text views that will hold strings
TextView txtSurname = (TextView) personView
.findViewById(R.id.txtSurname);
TextView txtFirstname = (TextView) personView
.findViewById(R.id.txtFirstname);
RatingBar ratingBar = (RatingBar) personView
.findViewById(R.id.ratingBar1);
//Once selected, get the question which the rating is in
//Start asynctask and get all the details for that question to update
//Send and update rating
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser)
{
ratingBar.setRating(rating);
String name = people.get(position).surname;
Toast.makeText(getContext(),
"Rating set to: " + rating + " for the position: " + position + " and user: " + name, Toast.LENGTH_SHORT).show();
}
});
// set text fields
txtSurname.setText(people.get(position).surname);
txtFirstname.setText(people.get(position).firstName);
float rate = ratingBar.getRating();
Toast.makeText(getContext(),
"Rating is: " + rate, Toast.LENGTH_LONG).show();
people.get(position).rating = rate;
System.out.print(people.get(position).rating);
// return view to ListView to display
return personView;
}
我知道我的答案与我的实际问题没有直接关系,但是如果有人遇到过相同使用对话框的问题,那么就有一个解决方案。