Pergunta

I have a Checkbox that will be the button Follow/Following of my app. How can I change the text of this button in the XML file without have to create a image for that? Is this possible?

Here is my code:

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


    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/follow_card" android:state_checked="false">

        </item>
        <item android:drawable="@drawable/following_card" android:state_checked="true"/>
        <item android:drawable="@drawable/follow_card"/>
    </selector>

Follow_card/Following_card are two diferent XML drawable files defining the shape of the button

Foi útil?

Solução

I'd do it programmatically. As the other comment says, you'll need to create an onClickListener, this way:

CheckBox your_checkbox = (CheckBox) findViewById(R.id.your_checkbox_id);
your_checkbox.setOnClickListener(new OnClickListener() { 
  @Override
  public void onClick(View view) {
    if (view.isChecked())
      your_checkbox.setText("Hey I'm checked!");
    else
      your_checkbox.setText("I'm not checked!");
  }
});  
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top