2015-12-07 6 views
5

私はアンドロイドアプリを実装しています。評価ボタンをクリックすると、私は電話をかけたり、断片をポップアップしたりします。ボタンをクリックすると、フラグメントを呼び出すかポップアップする方法

たとえば、ここではスクリーンショットを添付しました。私はこの

enter image description here

enter image description here

のようなポップアップまたはそのフラグメントをコールするので、どのようにレートボタンを上にクリックすると、これらの断片を呼び出す方法を私を助けてください?

+0

あなたのコードを表示してください –

+0

私はコードを書かなかった。 @IntelliJ Amiya –

答えて

2

ポップアップが表示されるように別のレイアウトを設計して、それをアライメントすることが必要です。あなたのデザインを作成したらここに例のレイアウト

<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> 

を新しいXMLファイルdialogue.xmlを作成しています。ボタンをクリックすると、それを呼び出す必要があります。以下のあなたの現在のレイアウトをオーバーレイとしてこれを実装することができ、対話に

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

+0

こんにちは@Anu、どうしたらいいの? –

+0

ボタンとテキストをこのダイアログに追加して追加する方法は? –

+0

linearlayoutを使用し、その向きをVerticalとして設定し、textViewとボタンを追加することができます。 – Anu

0

を表示する例です。実装ごとに異なる可能性があります。

私は、次のアプローチを使用して、これを実装:

<RelativeLayout> <- This is the parent 

    <RelativeLayout id="actual_layout"> <- This is where you will implement the layout 
      <!--Implement your layout here--> 
    </RelativeLayout> 

     <RelativeLayout id="rating_container" 
     visibility="gone" 
     background="#BB000000"> <- This is to set the translucent black background 
      <RelativeLayout id="rating_dialog" 
      alignParnetTop="true"> <- This is the rating dialog 
        <!--Your implementation here--> 
      </RelativeLayout> 
    </RelativeLayout> 

</RelativeLayout> 

今すぐあなたの 『評価』ボタンのonclickの中に「rating_container」の表示を切り替えます。

ratingButton.setOnCLickListener(new view.OnCLickListener(){ 
    @Override 
    public void onCLick(View v){ 
     toggleRatingContainer(true); 
    } 
}); 

この方法で要件を実装できます。あなたがこれについてもっと助けを必要とするかどうか私に教えてください。

注:完全なコードは書いていません。また、私はチェックしませんでしたが、すべてを直接入力しました。

EDIT

public void toggleRatingContainer(boolean showRatingDialog){ 
    ratingContainer.setVisibility((showRatingDialog)?View.VISIBLE:View.GONE); 
} 

ここで、 "ratingContainer" あなたはあなたの中に取得することができますID "rating_container" と "RelativeLayout" です:

次のようにあなたはtoggleRatingContainerを実装することができますアクティビティのonCreateメソッド。

また、引数として "false"を渡して同じメソッドを呼び出して、 "Submit"または "Cancel"ボタンをクリックしたときに、その可視性を "View.GONE"に切り替えることができます。

+0

Hey @Wanted、ここでtoggleRatingContainer()メソッドはエラーを表示しています。Cann'tメソッドtoggleRatingContainer(boolean)を解決します。どのようにそれを解決するには? –

+0

ちょっと@Rajendra、私は答えを編集しました。私は構造だけを与えました。ここで完全なコードを書いていないので、私が擬似コードとして書いたコードを扱ってください。実際の実装は、実装に応じて異なる場合があります。これは、要件を実装するために従うことができるアプローチの1つに過ぎません。あなたがこれについてもっと助けを必要とするかどうか私に教えてください。ハッピーコーディング! – Wanted

+0

それは動作していません...私はボタンにclilckedので、RelativeLayoutはメインレイアウトの下に表示されます。 –

関連する問題