i've used alert dialog star rating bar in it.but can't change number of stars being displayed(now displays 6..i want 5)..
there no corresponding xml rating bar because dynamically made. ive tried setnumstars() method no use....also tried changing wrapcontent.
here code..please help
enter code here protected void showratingalert() { // todo auto-generated method stub alertdialog.builder ab = new alertdialog.builder(androidloadimagefromurlactivity.this); ab.settitle("enter rating");ab.setmessage("stars"); final ratingbar rat = new ratingbar(androidloadimagefromurlactivity.this); rat.setnumstars(5); linearlayout.layoutparams lp = new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content,linearlayout.layoutparams.wrap_content); rat.setlayoutparams(lp); ab.setview(rat); ab.seticon(r.drawable.ic_launcher); ab.setpositivebutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { // todo auto-generated method stub float val = rat.getrating(); if(ur.equals("0")) { nr = val; } else { nr = (art+val)/2; }
from ratingbar
docs:
sets number of stars show. in order these shown properly, recommended layout width of widget wrap content.
http://developer.android.com/reference/android/widget/ratingbar.html#setnumstars(int)
so in case can create layout, instance layout/rating.xml
:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/root" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ratingbar android:id="@+id/ratingbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:numstars="5"/> </linearlayout>
and use layout dialog context. here modified dialog's code:
protected void showratingalert() { // todo auto-generated method stub alertdialog.builder ab = new alertdialog.builder(androidloadimagefromurlactivity.this); ab.settitle("enter rating");ab.setmessage("stars"); //inflating layout , finding ratingbar widget view root = ((layoutinflater) androidloadimagefromurlactivity.this.getsystemservice(context.layout_inflater_service)).inflate(r.layout.rating, null); ab.setview(root); final ratingbar rat = (ratingbar)root.findviewbyid(r.id.ratingbar); rat.setnumstars(5); ab.seticon(r.drawable.ic_launcher); //and existing code ...
Comments
Post a Comment