2

RatingBar を使用して AlertDialog を実行しようとしていますが、修正方法がわからないというエラーが表示されます。これが私のコードです:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getString(R.string.messageAskFB))
    .setCancelable(true)
    .setPositiveButton("Post on Facebook", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            try {
                Intent act = new Intent (RutaActualActivity.this, ActualizaEstado.class);
                act.putExtra(getString(R.string.package_name), mens);
                startActivity(act);
                } catch (Throwable e) {
                    e.printStackTrace();
                }

            }
    });

LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.layout_dialog, (ViewGroup) getCurrentFocus());
final int id_poiii=p.getId_poi();

builder.setView(dialoglayout);

AlertDialog lala = builder.create();

RatingBar rat = (RatingBar) lala.findViewById(R.id.dialogRatingBar);
rat.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { 

    public void onRatingChanged(RatingBar ratingBar, float rating,  boolean fromUser) { 
        TaskRating rattask = new TaskRating();
        rattask.execute(id_poiii,ratingBar.getNumStars());
    } 
});

Button buttpost = (Button) lala.findViewById(R.id.dialogfacebook);
buttpost.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        Intent act = new Intent (RutaActualActivity.this, ActualizaEstado.class);
        act.putExtra(getString(R.string.package_name), mens);
        startActivity(act);
    }
});


lala.show();

layout_dialog の XML は次のとおりです。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/dialogfacebook"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/titleAskFB" />

    <TextView
        android:id="@+id/dialogTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/rate_this_point"
        android:textSize="20sp" />

    <RatingBar
        android:id="@+id/dialogRatingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

</LinearLayout>

問題は、「rat」と「buttpost」の findViewById が null であり、その評価バーとボタンにリスナーを追加する別の方法がわからないことです。何か案は?どんな助けでも大歓迎です。どうもありがとう!

4

1 に答える 1

1

AlertDialogレイアウトからButtonとRatingBarを見つけてみてください:

RatingBar rat = (RatingBar) dialoglayout.findViewById(R.id.dialogRatingBar);

Button buttpost = (Button) dialoglayout.findViewById(R.id.dialogfacebook);
于 2013-01-12T15:40:09.337 に答える