0

我的问题的主要目的是知道将 OnRatingBarChangeListener 放在 UIL 中的哪个位置。在每张图片下方我添加了 ratingBars(它正在工作),接下来我应该做的是听取用户对 ratingbar 选择的操作。您的帮助将不胜感激。

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

原木猫:

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()

4

1 回答 1

0

因为我需要在我的 ratingBar 中放置一个听众,所以我必须在setOnRatingBarChangeListener里面放一个getView()

holder.br.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
            public void onRatingChanged(RatingBar ratingBar, float rating,
                    boolean fromUser) {

              }
            });
于 2013-08-02T03:21:21.623 回答