RadioButton子弹是看不见的

时间:2017-10-30 23:05:00

标签: android

我试图自定义对话框片段:

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_edit_order, null);
    if (view != null) {
        RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
        recyclerView.setHasFixedSize(true);

        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);

        mAdapter = new RadioButtonCustomAdapter(values);
        recyclerView.setAdapter(mAdapter);
    }

    return new AlertDialog.Builder(getActivity())
            .setTitle(R.string.edit_order_title)
            .setView(view)
            .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    editOrder();
                }
            })
            .setNegativeButton(R.string.cancel, null)
            .show();
}

结果如下:

enter image description here

但是,如果我使用活动,则代码为:

public class TestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        List<Item> values = getIntent().getParcelableExtra("a");


        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setHasFixedSize(true);

        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);

        RadioButtonCustomAdapter mAdapter = new RadioButtonCustomAdapter(values);
        recyclerView.setAdapter(mAdapter);
    }
}

结果如下:

enter image description here

正如您所看到的,可以在活动中看到bulet,并且使用对话框是不可见的。

两者共享相同的xml代码和相同的RecyclerView和Adapter。 为什么使用对话框看不到子弹?

XML:

Recyclerview(两者都相同):

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

recyclerview项目:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RadioButton
        android:id="@+id/radio_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="@dimen/min_height_radio_button"
        android:textSize="@dimen/text_size_radio_button" />

    <TextView
        android:id="@+id/value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:minHeight="@dimen/min_height_radio_button"
        android:textColor="@android:color/black"
        android:textSize="@dimen/text_size_radio_button"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="@id/radio_button"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/radio_button" />
</android.support.constraint.ConstraintLayout>

0 个答案:

没有答案