Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call or pop up fragment upon button click [closed]

I am implement an android app. I want to call or pop-up fragment upon rating button click.

For example, Here I attached screenshot. When I click up on the rate button so how to call pop-up or fragment like this

enter image description here

enter image description here

Please help me how to call these fragment?

like image 393
rajendra pawar Avatar asked Dec 07 '15 07:12

rajendra pawar


People also ask

How do you call a fragment from a button?

Something like this: Fragment someFragment = new SomeFragment(); FragmentTransaction transaction = getFragmentManager(). beginTransaction(); transaction.

Can we call fragment without activity in Android?

Android app must have an Activity or FragmentActivity that handles the fragment. Fragment can't be initiated without Activity or FragmentActivity.

How do you call an activity inside a fragment?

Best way of calling Activity from Fragment class is that make interface in Fragment and add onItemClick() method in that interface. Now implement it to your first activity and call second activity from there.


1 Answers

You need to design another layout only for the pop up to be shown and make it alignparenttop. Here is the example layout

Create new xml file dialogue.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLyt"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="#FFFFFF"
        android:paddingTop="10dp" >

        <TextView
            android:id="@+id/close"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="Fill in your design in this place"
            android:textSize="10dp" />


    </RelativeLayout>

</RelativeLayout>

Once you have created your design. You need to call it in your onbutton click. Following is the example to show a dialogue

ratingButton.setOnCLickListener(new view.OnCLickListener(){ 
    @Override 
    public void onCLick(View v){
         final Dialog fbDialogue = new Dialog(ProfileActivity.this, android.R.style.Theme_Black_NoTitleBar);
            fbDialogue.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(100, 0, 0, 0)));
            fbDialogue.setContentView(R.layout.facebook_dialogue);
            fbDialogue.setCancelable(true);
            fbDialogue.show();
    } 
}); 


    Hey I have put the code in onclicklistener. Check it . The above code works perfectly fine for me. As per my requirement I wanted the dialogue on the bottom of the screen . I have just made few lines of code change above to meet your requirement. My requirement was something like this   

enter image description here

like image 66
Anudeep Avatar answered Sep 29 '22 06:09

Anudeep