我的问题的主要目的是知道将OnRatingBarChangeListener放在UIL中的位置。在每张图片下面我添加了ratingBars(工作正常),接下来要做的就是听取用户对评级栏选择的操作。非常感谢您的帮助。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_image_grid);
Bundle bundle = getIntent().getExtras();
imageUrls = bundle.getStringArray(Extra.IMAGES);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
listView = (GridView) findViewById(R.id.gridview);
rbar = (RatingBar)findViewById(R.id.ratingBar1);
((GridView) listView).setAdapter(new ImageAdapter());
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startImagePagerActivity(position);
Toast.makeText(getBaseContext(), "Clieckeed",Toast.LENGTH_SHORT).show();
Log.d("Inside Onclick:", view.toString());
}
});
rbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(getBaseContext(), "Rating:"+rating, Toast.LENGTH_SHORT).show();
}});
}
填充视图
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
final ViewHolder holder;
if (convertView == null) {
view = getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
holder = new ViewHolder();
holder.text = (TextView) view.findViewById(R.id.text1);
holder.image = (ImageView) view.findViewById(R.id.imageView1);
holder.br = (RatingBar) view.findViewById(R.id.ratingBar1);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.text.setText("NAAA NA");
holder.br.setStepSize(1);
holder.br.setFocusable(false);
Log.d("Image Path Value in GridView: ", imageUrls[position].toString());
imageLoader.displayImage(imageUrls[position], holder.image, options);
return view;
}
Log Cat:
07-11 09:41:16.783: E/AndroidRuntime(31846): FATAL EXCEPTION: main
07-11 09:41:16.783: E/AndroidRuntime(31846): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jinisys.restoplusordering/com.restoplus.galleryuil.ImageGridActivity}: java.lang.NullPointerException
07-11 09:41:16.783: E/AndroidRuntime(31846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
07-11 09:41:16.783: E/AndroidRuntime(31846): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-11 09:41:16.783: E/AndroidRuntime(31846): at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-11 09:41:16.783: E/AndroidRuntime(31846): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-11 09:41:16.783: E/AndroidRuntime(31846): at android.os.Looper.loop(Looper.java:137)
07-11 09:41:16.783: E/AndroidRuntime(31846): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 09:41:16.783: E/AndroidRuntime(31846): at java.lang.reflect.Method.invoke(Method.java:511)
07-11 09:41:16.783: E/AndroidRuntime(31846): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-11 09:41:16.783: E/AndroidRuntime(31846): at dalvik.system.NativeStart.main(Native Method)
07-11 09:41:16.783: E/AndroidRuntime(31846): Caused by: java.lang.NullPointerException
07-11 09:41:16.783: E/AndroidRuntime(31846): at com.restoplus.galleryuil.ImageGridActivity.onCreate(ImageGridActivity.java:70)
07-11 09:41:16.783: E/AndroidRuntime(31846): at android.app.Activity.performCreate(Activity.java:5008)
07-11 09:41:16.783: E/AndroidRuntime(31846): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-11 09:41:16.783: E/AndroidRuntime(31846): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
07-11 09:41:16.783: E/AndroidRuntime(31846): ... 11 more
第70行是代码rbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
答案 0 :(得分:0)
由于我需要在我的ratingBar中添加一个监听器,然后我必须在setOnRatingBarChangeListener
getView()
holder.br.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
}
});