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 に答える