Search code examples
androidprogress-barandroid-dialogfragment

how to show the progress bar in my DialogFragment ?


I have created dialogfragment in my layout I have added the Progressbar and need to visible in my dialog fragment. but it's not detect inside my dialogfragment

This is my layout

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<RelativeLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#99ffffff">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_margin="30dp"
        android:background="@color/white"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity"
            android:text="@string/invite_consumer"
            android:textColor="@color/veryDarkGrey"
            android:textSize="@dimen/button_text_size"
            app:font="@{@string/font_roboto_bold}" />


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:id="@+id/top"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="10dp">
                    <!--din 77-->
                    <EditText
                        android:id="@+id/firstName"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/first_name"
                        android:imeOptions="actionNext"
                        android:lines="1"
                        android:padding="5dp"
                        android:paddingLeft="10dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />

                    <EditText
                        android:id="@+id/surname"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/surname"
                        android:imeOptions="actionNext"
                        android:lines="1"
                        android:padding="5dp"
                        android:paddingLeft="10dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />

                    <EditText
                        android:id="@+id/email"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/email"
                        android:imeOptions="actionNext"
                        android:inputType="textEmailAddress"
                        android:lines="1"
                        android:padding="5dp"
                        android:paddingLeft="10dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />

                    <EditText
                        android:id="@+id/mobile"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/mobile_number"
                        android:inputType="phone"
                        android:imeOptions="actionNext"
                        android:lines="1"
                        android:padding="5dp"
                        android:paddingLeft="10dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />

                    <EditText
                        android:id="@+id/vehicleId"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/height_row"
                        android:layout_marginTop="10dp"
                        android:background="@null"
                        android:hint="@string/vehicle_id"
                        android:imeOptions="actionDone"
                        android:lines="1"
                        android:padding="5dp"
                        android:singleLine="true"
                        android:textColor="@color/veryDarkGrey"
                        android:textSize="@dimen/normal"
                        app:font="@{@string/font_roboto_bold}" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/viewColor" />
                    <!--din 49-->
                </LinearLayout>

                <Button
                    android:id="@+id/submit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@+id/top"
                    android:layout_marginTop="@dimen/activity"
                    android:background="@drawable/sel_rounded_rectangular_yellow"
                    android:gravity="center"
                    android:minHeight="@dimen/min_touch"
                    android:text="@string/submit"
                    android:textAllCaps="false"
                    android:textColor="@color/white"
                    android:textSize="@dimen/button_text_size"
                    app:font="@{@string/font_roboto_regular}" />
            </RelativeLayout>

        </ScrollView>

    </LinearLayout>

    <ProgressBar
    android:id="@id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="visible"/>
</RelativeLayout>

My dialogFragment like this

public class PopupInviteConsumerDialog extends BaseDialog implements View.OnClickListener {
private InviteConsumerDialogBinding mBinding;
private Context mContext;

public static PopupInviteConsumerDialog newInstance(Context context) {
    PopupInviteConsumerDialog dialog = new PopupInviteConsumerDialog();
    dialog.mContext = context;
    return dialog;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);

    mBinding = DataBindingUtil.inflate(inflater, R.layout.invite_consumer_dialog, container, false);

    setCancelable(false);
mBinding.progressBar.setVisibility(View.VISIBLE);
    mBinding.submit.setOnClickListener(this);

    return mBinding.getRoot();
}

@Override
public void onStart() {
    super.onStart();
    getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.submit:
            submit();
            break;
    }
}

@Override
public Dialog onCreateDialog(@NonNull Bundle savedInstanceState) {
    return new Dialog(getActivity(), getTheme()) {
        @Override
        public void onBackPressed() {
            dismiss();
        }
    };
}

Here I need to show the progressbar like calling mBinding.progressBar.setVisibility(View.VISIBLE); But it will not allow to call this. Any suggestion to call the progressbar


Solution

  • I think id declaration problem

    change

    android:id="@id/progressBar" to android:id="@+id/progressBar"

    and try