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
Please help me how to call these fragment?
Something like this: Fragment someFragment = new SomeFragment(); FragmentTransaction transaction = getFragmentManager(). beginTransaction(); transaction.
Android app must have an Activity or FragmentActivity that handles the fragment. Fragment can't be initiated without Activity or FragmentActivity.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With