The background color of the textview does not change when clicked in popupwindow

I am using PopUpwindow with textviews in it. Problem. When I click on any of the text elements, the background color does not change, although it changes when the text image is focused, but not pressed.

After clicking, I fire popupwindow, and if I don't reject popupwindow, the background color changes according to the selector:

This is my textview background selector:

<item android:state_focused="true" android:drawable="@drawable/focused" />    
<item android:state_pressed="true" android:drawable="@drawable/pressed" />
<item android:drawable="@drawable/priornone" /> <!-- default --> </selector> 

in my popupwindow all i do is:

TextView manage_list = (TextView)popupView.findViewById(R.id.manage_lists);
manage_list.setOnClickListener(new View.OnClickListener(){

public void onClick(View v) 
{

  Intent myIntent = new Intent(v.getContext(),ManageList.class);
      popupWindow.dismiss();
  startActivity(myIntent);

 }});

layout file for popupwindow:

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

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
  android:background="@drawable/pop_menu_bg"
 android:orientation="vertical"
    >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/manage_lists"
    android:text="Manage lists"
    android:background="@drawable/my_drawable"
 >
 </TextView>


</LinearLayout>

This is a rather strange behavior, everything works well, if I do not reject popupwindow, but if I dismiss popupwindow on a click, the background text does not change.

What am I doing wrong? Any help would be appreciated.

+5
source share
4 answers

, , :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/focused" />
<item android:state_pressed="true" android:drawable="@drawable/activated" /> 
<item android:drawable="@drawable/priornone" />
</selector>

.

, .

0

// android:state_pressed="true", android:state_focused="true" .

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/button_pressed" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/button_focused" /> <!-- focused -->
    <item android:state_hovered="true"
          android:drawable="@drawable/button_focused" /> <!-- hovered -->
    <item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>

. :

: Linringayout android:clickable="false"

0

You will use your TextView as a flag, right?

Use this boolean flag to try this.

private boolean clicked = false;

// ...

mytextView.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v){
        clicked = !clicked;

        if(clicked){
            mytextView.setBackgroundColor(yourcolorclicked);
        }else{
            mytextView.setBackgroundColor(yourcolorunclicked);
        }
        mytextView.invalidate();
    }
});
0
source

Check if you have a name conflict. In the event that none of your changes appears, the possibility of it not working due to any problem with names that conflict with the imported library may be your main problem.

0
source

All Articles