Setting Imageview Background Issue With Selector
Solution 1:
I encountered this issue too, I solved it using the tecnique here:
http://android.cyrilmottier.com/?p=525
Look at the paragraph "Don't press everything!"
Solution 2:
You should try using android:duplicateParentState="false"
to indicate not to use the parent's drawable state for its child.
<ImageView
android:id="@+id/skinEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="@android:drawable/ic_menu_edit"
android:layout_centerInParent="true"
android:duplicateParentState="false"
/>
Update
Make your button's immediate parent non-clickable, i.e. add android:clickable="false"
to it in row.xml and see if that fixes the problem. Now the click on item will not change the button state. But the click on button should still work I guess.
update
<ImageButtonandroid:id="@+id/skinEdit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:src="@android:drawable/ic_menu_edit"android:scaleType="center"android:background="@android:drawable/state_redblue_drawable"android:padding=10dpandroid:clickable="true"/>
Solution 3:
I found this solution before.. I dont have the link, but you has to do this. Create a custom class for the linearlayout that contains your botton, then override the setPressed state to dont do anything;
publicclassUnpresseableLinearLayoutextendsLinearLayout
{
publicUnpresseableLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@OverridepublicvoidsetPressed(boolean pressed)
{
// Do nothing here. Specifically, do not propagate this message along// to our children so they do not incorrectly display a pressed state// just because one of their ancestors got pressed.
}
}
this will solve the problem because the android:duplicateParentState="false" will not work in this case.
Replace then your linearlayout in your xml with this one, that cannot receive press actions
Edit: Sorry, i just saw that you are using RelativeLayout.. but i supose that is the same.
Solution 4:
try making imageView clickable...
<ImageView
android:id="@+id/skinEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="@android:drawable/ic_menu_edit"
android:layout_centerInParent="true"
android:focussable="false"
android:focussableInTouchMode="false"
android:clickable="true" />
or..
change selector state to
<selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_selected="true"android:drawable="@color/blue" /><itemandroid:drawable="@color/red"/></selector>
Solution 5:
Ok. First of all Sorry for the Late reply.
Before going on solution let see what i get from your question.
You want is, when you click on List-items then that red image not convert in to Blue and if user click on the Red Image then it should be convert in to the Red. But not with whole list-Items right ???
If is it so, then there is nothing to do more.
Don't put selector. Selector is basically for, whenever you want to change the color of the background while you click on that particular view.
And yes if you want to change the color of the RedImage while user click on it then again don't use selector there. But Just change the Color of that Image during run time.
As like:
@OverridepublicvoidonClick(View view) {
YOUR_VIEW.setBackgroundColor(0xffff0000);
}
Hope it will help you. If its not work as what you want then let me know.
i will like to help you.
Enjoy.:)
Post a Comment for "Setting Imageview Background Issue With Selector"