Android 在使用分级栏时,如何使用自定义ListView将最高分级的项目显示到另一个活动中?
我制作了一个Android评级栏程序来接受用户评级,计算总评级,并在指标评级栏中显示 现在,我想在我的评级栏程序中再添加两项功能:Android 在使用分级栏时,如何使用自定义ListView将最高分级的项目显示到另一个活动中?,android,android-layout,android-intent,android-emulator,android-widget,Android,Android Layout,Android Intent,Android Emulator,Android Widget,我制作了一个Android评级栏程序来接受用户评级,计算总评级,并在指标评级栏中显示 现在,我想在我的评级栏程序中再添加两项功能: 我想在ListView中使用现有的分级栏 其次,希望在另一项活动(如MyRatings)中显示从高到低的评分项目 我的Java代码:- public class InteractiveRatingBarActivity extends Activity implements OnRatingBarChangeListener { RatingBar getRatin
public class InteractiveRatingBarActivity extends Activity implements
OnRatingBarChangeListener {
RatingBar getRatingBar;
RatingBar setRatingBar;
TextView countText;
int count;
float curRate;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewsById();
setRatingBar.setRating(curRate);
getRatingBar.setOnRatingBarChangeListener(this);
}
private void findViewsById() {
getRatingBar = (RatingBar) findViewById(R.id.getRating);
setRatingBar = (RatingBar) findViewById(R.id.setRating);
countText = (TextView) findViewById(R.id.countText);
}
public void onRatingChanged(RatingBar rateBar, float rating,
boolean fromUser) {
DecimalFormat decimalFormat = new DecimalFormat("#.#");
curRate = Float.valueOf(decimalFormat.format((curRate * count + rating)
/ ++count));
Toast.makeText(InteractiveRatingBarActivity.this,
"New Rating: " + curRate, Toast.LENGTH_SHORT).show();
setRatingBar.setRating(curRate);
countText.setText(count + " Ratings");
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RatingBar
android:id="@+id/getRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0" />
<RatingBar
android:id="@+id/setRating"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/getRating"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.1" />
<TextView
android:id="@+id/countText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/getRating"
android:layout_toRightOf="@+id/setRating"
android:paddingLeft="10dp" />
</RelativeLayout>
你面临的问题在哪里?@Luksprog,我不知道如何使用listview在另一个活动中显示从高到低的评分项目,就像上面的代码一样,我没有使用listview,只是简单地计算给出的评论数,但坦率地说,没有存储在任何内容中,因此,请帮助我展示一些代码,并给出实现该目标的一些方向。Well,你没有任何东西需要评分,没有对象没有任何东西,因此请尝试更好地解释,并提供更多有关评分项目的信息。带有排序评级的ListView
很容易让您需要制作一个自定义适配器。@Luksprog谢谢,我会试试的,明天再给您回复。.现在再见。.您应该将它们保存在arraylist或hashmap中,。。。并传递该变量(即使用StaticClass在不同的活动/类之间保存变量)或(视情况而定)在调用方活动中创建一个方法(将活动作为listviewadapter的参数传递),并使用相同的方法或活动的另一个方法对listview排序并刷新它。