Android Question Center Rating Bar within Dialog

Fusseldieb

Active Member
Licensed User
Longtime User
Hi community,
I'm trying and trying, but I don't come to a solution.
I want to make a rating bar centralized within a dialog, using the "BetterDialogs" lib.
I have made the dialog and the rating bar, but it wont fit centralized.
(Image attached)
Has anyone a solution?
PS: The rating bar doesn't give me his Width + Height... So I can't calculate the center of this thing.

Thanks in advance ;)
 

Attachments

  • Screenshot_2014-10-29-20-16-22[1].png
    Screenshot_2014-10-29-20-16-22[1].png
    106.2 KB · Views: 362

LucaMs

Expert
Licensed User
Longtime User
Add this code to the RatingBarClass Module:

B4X:
Sub getWidth As Int
    Return mBase.Width
End Sub

Sub getHeight As Int
    Return mBase.Height
End Sub


(The most proper place, if you are using version 1.2, is after:
B4X:
#Region Class Specific Get/set

but it is ok elsewhere too).
 
Upvote 0

Fusseldieb

Active Member
Licensed User
Longtime User
@LucaMs It doesn't work. It gives me a error.
Unexpected event (missing RaiseSynchronousEvents): rb_ratingchanged


Check the unfiltered logs for the full stack trace.
Error occurred on line: 145 (ratingbarclass)
java.lang.NullPointerException


at anywheresoftware.b4a.objects.ViewWrapper.getWidth(ViewWrapper.java:128)
at vtapps.funnyjokes.ratingbarclass._getwidth(ratingbarclass.java:290)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:4633)
at android.view.View$PerformClick.run(View.java:19330)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

What can this be?

Thanks in advance :)
 

Attachments

  • errror.jpg
    errror.jpg
    340.5 KB · Views: 170
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
upload_2014-11-1_1-42-23.png

This means that the customview (RatingBar) has not yet been initialized.


Since I do not use BetterDialogs nor RatingBar, I suggested to you how to get the width and height of a view which you own the source code (the class).
The problem is that RatingBar was created to be used in the Designer, rather BetterDialogs allows you to add views by code.

To do this you need to change the class RatingBar.

If I do not I fall asleep :D, I'll try to change it.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The problem is that RatingBar was created to be used in the Designer

This is wrong. RatingBar can be also added by code.

I have done some tests.

It seems to me that the BetterDialogs does not center the view. You should ask the author (Informatix).

RatingBar is always aligned to the left. I can't solve, sorry.

I added a function to the class RatingBar: AsView.

Better than that, at this time (3:16 AM!), I can not help you, sorry.
 

Attachments

  • lm BD and RB.zip
    14 KB · Views: 177
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I did not understand your statement.

I meant to say that replicate, imitate a RatingBar view is simple: a panel with 5 images.

In your case, you can do as Informatix suggested:
you can create a specific layout with a panel and 5 imageview and load it in BetterDialog as in his example:
B4X:
Dim pnlBody As Panel
pnlBody.Initialize("")
pnlBody.LoadLayout("corps") ' <--- your layout. "layMyRatingBar" instead of "corps", for example.


What kind of event RatingBar raises? One only, RatingChanged.
It raises when you set the value in the code or the user touches one star.

Just one little problem: half stars; to exactly replicate RatingBar, you should use 5 panels instead of 5 images,
so you are able to check where the "star" has been touched,
before or after the middle of its width (panel touch event, if x< pnlStar.Width / 2 then HalfStar = true)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I tried to make a RatingBar.

It is far from perfect.

The adaptation of the stars should be improved and should be added a feature to adjust the size of the view to the size of the images of the stars.

The aim is to center the stars, as mentioned in previous posts.

If someone want to fix it... I have already wasted too much time (at all).
 

Attachments

  • lm RatingBar.zip
    99.2 KB · Views: 168
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
But I don't understand what you want to achive: RatingBar? RatingBar inside a dialog? Why "slide"? With RatingBar you may want set a value through touch or code.

(Out of topic: there some English expert here? How should I write:

I can set it...
a) Through code
b) by code
c) via code
d) from code

)

:D
 
Upvote 0

Fusseldieb

Active Member
Licensed User
Longtime User
Last edited:
Upvote 0
Top