Monday, July 11, 2011

Tricky list item highlighting issue - solved :)

Ok, so, now with our memory leak solved, we're back in the business of ironing out bugs. There are a few things I still need to do:

1) Turn off highlighting once the answer has been selected
2) Get rid of the "next" button
3) Probably implement Spaced repetition. All the kids are doing it.
4) Get a pure Japanese font in there

Here is the layout for the list item.


style="@style/CodeFont"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30sp"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:paddingLeft="20dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:background="#AAEBD5A8"
/>



If I delete the background, the highlight color reverts to orange. But, how to I change the background/highlight to transparent?

Well, if I do something like this:

int childCount = listView.getChildCount();

for (int i = 0; i < childCount; i++){
View v = listView.getChildAt(i);
v.setBackgroundResource(R.drawable.my_drawable_background);
}

and create a my_drawable_background which looks like this:

android:shape="rectangle">
android:startColor="#FFEBD5A8"
android:endColor="#FFEBD5A8"
android:angle="90"/>







Then, the highlight doesn't make any difference, because it's the same color as the background at that point, if you don't press on the highlighted green. But, if you do, it momentarily has a kind of ugly brownish tinge.

The obvious answer is to set it to transparent, but that actually makes it orange. Let's double check that.

android:shape="rectangle">
android:startColor="#00EBD5A8"
android:endColor="#00EBD5A8"
android:angle="90"/>





Yeah, it goes to orange.

Ok, how about this post on SO
http://stackoverflow.com/questions/4888871/how-to-change-selected-listitem-color



create a selector_file_name.xml and place on drawable folder . the content of that file (im using it with my custom drawable/images) . the idea is that you have to edit the android:states_..... with your own colors or drawables/images.

the content of that file is


< xml version="1.0" encoding="utf-8"?>

android:state_pressed="true"
android:drawable="@drawable/strishe_dhe_shigjete_bosh" />
android:state_selected="true"
android:drawable="@drawable/strishe_dhe_shigjete_bosh" />
android:drawable="@color/white"/>


and then on the main layout file ( where you have the listview) you set the

android:background="@drawable/selector_file_name"


Keeping in mind that I want to do this only after the question is answered.


I have an idea. Just change the selected color for the correct one! That's the only one I care about, anyway.

No, not so simple - that's what I'm already doing. No, I have to change it with a selectable also:


android:drawable="@drawable/hilight_gradient_correct_drawable" />
android:drawable="@drawable/hilight_gradient_correct_drawable" />



Where hilight_gradient_correct_drawable is:

android:shape="rectangle">
android:angle="90" />



And in the code, basically,

correctRow = listView.getChildAt(i);

correctRow.setBackgroundResource(R.drawable.hilight_gradient_correct_selector);

Let's try it out...

Nope. The same problem exists.

The problem is that the initial background for the item somehow remains in effect.

Ah, I see what the problem is, at last. I was including a gradient in the "correct", so it's not pure green. I still like the gradient, but when the background highlight, which is kind of a brownish-tan shows through, it clashes.

How about this?

hilight_no_gradient_correct_drawable

android:shape="rectangle">
android:angle="90" />





android:drawable="@drawable/hilight_no_gradient_correct_drawable" />
android:drawable="@drawable/hilight_no_gradient_correct_drawable" />




Yes. That did it. Sweeter than sweet. Now, when I click on the (already) highlighted in green item, it switches to a non-gradient and gets rid of that kind of stained color.

Ok, that's a wrap for now.

No comments:

Post a Comment