Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Wednesday, March 19, 2014

RatingBar madness and solution!

I've been working with Android recently and I just ran into an irritating "quark" with the RatingBar object and I couldn't find a solution through the usual googling and StackExchange, fortunately I stumbled upon a solution!

The Problem:
The ratingBar has a numStars setting which should indicate the maximum number of stars to display for a rating. In my instance I have this value set to 5, only problem is it displays a many stars and it can possibly fit into the viewable space.. somewhere around 8 stars, uh... hello, I set it to 5! I love it when things are easy!


This wont do, So here's the code, perfectly reasonable stuff here. (For details on how to do a custom style check out this great blog post, no point in me rewriting this one.)

<RatingBar
android:id="@+id/rtbDvcMgmt"
style="@style/CustomRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_marginTop="5dp"
android:max="5"
android:maxHeight="50dp"
android:minHeight="28dp"
android:numStars="5"
android:rating="0.0"

android:stepSize="1.0" />

This code has nothing wrong with it, so why is it no working as expected? The explanation can be found in the RatingBar source code java doc!

When using a RatingBar that supports user interaction, placing widgets to the left or right of the RatingBar is discouraged.
What is meant by "discouraged" is it wont work! All sorts of things go wrong, the stars don't fill properly, there are more stars displayed then you requested... Yes don't do this, it doesn't work.

The cause in my case was that I was using a TextView next to the RatingBar because that's the requirement! I also had the whole form laid out in a Tablerow which doesn't play nicely with RatingBar either as I discovered when I moved the RatingBar onto its own row.

The Solution!
The solution is surprisingly simple. The RatingBar works when it's all by itself snuggled up in a Layout with nothing to the right or left. so I wrapped it in its own LinearLayout INSIDE of the TableRow with a TextView right next to it! That did the Trick!



<TableRow
android:id="@+id/tableRowDvcMgmt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5sp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
... />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RatingBar
android:id="@+id/rtbDvcMgmt"
style="@style/CustomRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:layout_marginTop="5dp"
android:max="5"
android:maxHeight="50dp"
android:minHeight="28dp"
android:numStars="5"
android:rating="0.0"
android:stepSize="1.0" />
</LinearLayout>
</TableRow>

Monday, June 6, 2011

A solution to speed up an old Droid

Is your Droid phone running so slow that you can barely answer a phone call before it rolls to voice mail? Yea that was my phone last week! I couldn't accomplish anything with my phone without long delays and that included just answering the phone! I have a venerable but, much loved Droid 1 and with 4 months remaining on the contract there was just no way I could "tough it out" at the current response time. Discussing the issue with a few Verizon reps got me the well worn mantra of the old Windows OS days, Reset (Just like Reinstall when you had Windows speed problems right?).

Fortunately, I found a better solution. I didn't want to invest the time into re-configuring and downloading everything on my phone, it's just the way I like it and I have better things to do such as working on my Game Programming or gaming with my son! I had freed up more memory then the average amount of free memory found on a Droid so I knew that the OS had enough space to do it's thing which lead me to suspect something was getting in the way of Androids ability to do things quickly. The first thing that came to mind? Cache. Nothing like a nice fat Cache full of useless junk to keep an old processor spinning its wheels right? Sure enough!

So my suggestion, before you reset your Android, clear the system Cache, it just might save you a couple hours! Here's the surprisingly easy Steps (Getting into the System Menu is specific to the Droid 1, but the steps should be the same on other Droids)

1. Turn the Droid off, take the battery out then place it back in.

2. Open the keyboard and press the X key while pressing and holding Power. The device will power on. Keep holding the buttons down until a yellow triangle appears on the screen.

3. Press and hold the Volume Up and then also press Camera button button to get to the "Android System Recovery" Menu.

4. Use the direction pad to the right of the keyboard to select the "wipe cache partition" (This is it right here!)

5. Once complete, use the direction pad to select the first option "reboot"


Believe it or not this did the trick! My phone has been running much faster, it's still a near two year old phone so its not as peppy as it once was but hey we all get a little bit slower with age...
Subscribe to: Comments (Atom)

AltStyle によって変換されたページ (->オリジナル) /