Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AlertDialog上的分级栏存在问题_Java_Android_Android Alertdialog_Ratingbar - Fatal编程技术网

Java AlertDialog上的分级栏存在问题

Java AlertDialog上的分级栏存在问题,java,android,android-alertdialog,ratingbar,Java,Android,Android Alertdialog,Ratingbar,我正在尝试使用分级栏进行AlertDialog,但我遇到了一个不知道如何修复的错误。这是我的密码: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getResources().getString(R.string.messageAskFB)) .setCancelable(true) .setPositiveButton("Post on Facebook", new D

我正在尝试使用分级栏进行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_对话框的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,我不知道向该分级栏和按钮添加侦听器的其他方法。有什么想法吗?任何帮助都将不胜感激。非常感谢

尝试从AlertDialog布局中查找按钮和分级栏:

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

Button buttpost = (Button) dialoglayout.findViewById(R.id.dialogfacebook);