Monday, December 19, 2011

Android Custom Dialog Box with a Ratting Bar

This is an example for updating rating on a dialog box.

Activity Code:
Button rankBtn = (Button) findViewById(R.id.rank_button);
rankBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
rankDialog = new Dialog(MyActivity.this, R.style.FullHeightDialog);
rankDialog.setContentView(R.layout.rank_dialog);
rankDialog.setCancelable(true);
ratingBar = (RatingBar)rankDialog.findViewById(R.id.dialog_ratingbar);
ratingBar.setRating(userRankValue);

TextView text = (TextView) rankDialog.findViewById(R.id.rank_dialog_text1);
text.setText(name);

Button updateButton = (Button) rankDialog.findViewById(R.id.rank_dialog_button);
updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rankDialog.dismiss();
}
});
//now that the dialog is set up, it's time to show it
rankDialog.show();
}
});

layout/rank_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="2dip">

<TextView android:text="Doctor's Name" android:id="@+id/rank_dialog_text1"
android:textSize="24dp" android:layout_marginTop="10dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"/>

<RatingBar
android:layout_marginTop="10dp" android:layout_marginBottom="10dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:clickable="true"
android:id="@+id/dialog_ratingbar" android:layout_gravity="center"
android:numStars="5" android:stepSize="1.0" android:rating="2"
android:isIndicator="false"/>

<Button android:id="@+id/rank_dialog_button"
android:layout_height="wrap_content"
android:text="Update" android:focusable="false"
android:layout_margin="5dip" android:textColor="#FFF8C6"
android:textSize="20dip" android:layout_width="fill_parent" />

</LinearLayout>

values/my_style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
</resources>

6 comments:

Sawan said...

Customize Android Search Dialog Using Library
In this tutorial, we are going to learn how to implement and customize android search dialog in our android application. Search functionality is one of the major features most android applications have.
http://www.tellmehow.co/customize-android-search-dialog/

soumya said...

It's intresting blog these tricks are helpful to everyone Android Online Training

Chiến SEOCAM said...

Den information du delar, för bra och intressant. Jag har tur att läsa den här artikeln

Phối chó bull pháp

Phối giống chó Corgi

Phối chó Pug

Dịch vụ phối giống chó Poodle

Dịch vụ phối giống chó bull pháp

Chiến SEOCAM said...

Веома сам сретан што видим овај чланак. Желим вам да увек будете срећни и срећни

giảo cổ lam giảm cân

giảo cổ lam giảm béo

giảo cổ lam giá bao nhiêu

giảo cổ lam ở đâu tốt nhất

Chiến SEOCAM said...

1 artículo es demasiado interesante. Gracias por compartir

máy khuếch tán tinh dầu

máy khuếch tán tinh dầu giá rẻ

máy phun tinh dầu

máy khuếch tán tinh dầu tphcm

máy phun sương tinh dầu

Chiến SEOCAM said...

1 bài viết quá hay và thú vị.

giảo cổ lam 5 lá

giảo cổ lam 7 lá

giảo cổ lam khô

giảo cổ lam 9 lá