main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>
<TableRow
android:id="@+id/tabrow_review">
<TextView android:id="@+id/yourreview" android:layout_width="wrap_content"
android:layout_height="70dip" android:text="Your Review"
android:gravity="center"
android:textStyle="bold"
android:layout_alignParentLeft="true"/>
<RatingBar android:id="@+id/ratingBar" style="?android:attr/ratingBarStyleSmall"
android:layout_gravity="center_vertical|center_horizontal"
android:focusable="true" android:layout_width="wrap_content"
android:layout_height="wrap_content"></RatingBar>
</TableRow>
</TableLayout>
review_rating.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="10dp"
android:id="@+id/layout_root">
<!-- <TextView android:id="@+id/comments" android:text="My Review Section"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
/>-->
<RatingBar android:id="@+id/reviewStars"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:numStars="5" android:stepSize="1" />
<TextView android:layout_width="fill_parent"
android:layout_height="10dip" />
<TextView android:layout_width="wrap_content"
android:layout_height="30dip"
android:layout_gravity="center"
android:id="@+id/rateval"/>
<TextView android:layout_width="fill_parent"
android:layout_height="10dip" />
<EditText android:id="@+id/reviewTitle"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Enter Title"
/>
<EditText android:id="@+id/reviewWriteText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:ems="13" android:hint="Enter a comment"
android:singleLine="false" android:lines="5"
/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<Button android:id="@+id/reviewWriteAccept" android:text="Submit Review"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_weight="1" />
<Button android:id="@+id/reviewWriteCancel" android:text="Close"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</ScrollView>
CustomDialog1Activity.java
package com.incept.customdialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
public class CustomDialog1Activity extends Activity {
static final int CUSTOM_DIALOG_ID = 0;
TextView customDialog_TextView,customDialog_Textval;
EditText customDialog_EditText;
Button customDialog_Update, customDialog_Dismiss;
RatingBar customDialog_Rating;
RatingBar outerrating;
String rating_value;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableRow review = (TableRow)findViewById(R.id.tabrow_review);
outerrating = (RatingBar)findViewById(R.id.ratingBar);
review.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
showDialog(CUSTOM_DIALOG_ID);
}
});
}
private Button.OnClickListener customDialog_UpdateOnClickListener
= new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
customDialog_TextView.setText(customDialog_EditText.getText().toString());
}
};
private Button.OnClickListener customDialog_DismissOnClickListener
= new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
dismissDialog(CUSTOM_DIALOG_ID);
}
};
private RatingBar.OnRatingBarChangeListener customDialog_RatingOnClickListener
= new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar paramRatingBar, float rating,
boolean paramBoolean) {
//Toast.makeText(CustomDialog1Activity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
rating_value=Float.toString(rating);
customDialog_Textval.setText(rating_value);
outerrating.setRating(rating);
}
};
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
Dialog dialog = null;;
switch(id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(CustomDialog1Activity.this);
dialog.setContentView(R.layout.review_rating);
dialog.setTitle("Review It!");
customDialog_EditText = (EditText)dialog.findViewById(R.id.reviewWriteText);
//customDialog_TextView = (TextView)dialog.findViewById(R.id.dialogtextview);
customDialog_Textval=(TextView)dialog.findViewById(R.id.rateval);
customDialog_Update = (Button)dialog.findViewById(R.id.reviewWriteAccept);
customDialog_Dismiss = (Button)dialog.findViewById(R.id.reviewWriteCancel);
customDialog_Rating = (RatingBar)dialog.findViewById(R.id.reviewStars);
customDialog_Update.setOnClickListener(customDialog_UpdateOnClickListener);
customDialog_Dismiss.setOnClickListener(customDialog_DismissOnClickListener);
customDialog_Rating.setOnRatingBarChangeListener(customDialog_RatingOnClickListener);
break;
}
return dialog;
}
}
No comments:
Post a Comment