[RESOLVIDO] Como setar o texto dos botões de um DatePickerDialog para PT-BR

7 respostas
R

Pessoal, estou numa aplicação onde preciso usar uma DatePickerDialog.

Estava seguindo o exemplo do site oficial do android mesmo: http://developer.android.com/resources/tutorials/views/hello-datepicker.html

Mas este, por padrão vem no formato americano, e os botões estão em ingles(“set” e “cancel”).

Não vejo como mudar o formato e o texto dos botões. Quem souber e puder dar uma ajuda, eu agradeço…

Segue o codigo.

private TextView mDateDisplay;
private Button mPickDate;
private int mYear;
private int mMonth;
private int mDay;

static final int DATE_DIALOG_ID = 0;
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);
// capture our View elements
    mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
    mPickDate = (Button) findViewById(R.id.pickDate);

    // add a click listener to the button
    mPickDate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DATE_DIALOG_ID);
        }
    });

    // get the current date
    final Calendar c = Calendar.getInstance();
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH);

    // display the current date (this method is below)
    updateDisplay();
}
// updates the date in the TextView

private void updateDisplay() {

mDateDisplay.setText(

new StringBuilder()

// Month is 0 based so add 1

.append(mMonth + 1).append("-")

.append(mDay).append("-")

.append(mYear).append(" "));

}
// the callback received when the user "sets" the date in the dialog
private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, int year, 
                                  int monthOfYear, int dayOfMonth) {
                mYear = year;
                mMonth = monthOfYear;
                mDay = dayOfMonth;
                updateDisplay();
            }
        };
<a class="mention" href="/u/override">@Override</a>

protected Dialog onCreateDialog(int id) {

switch (id) {

case DATE_DIALOG_ID:

return new DatePickerDialog(this,

mDateSetListener,

mYear, mMonth, mDay);

}

return null;

}

7 Respostas

F

Também tive esta dúvida a muito tempo a atrás e pelo o que me disseram não tem como. Você teria que criar o componente! :frowning:

Mas espero que seja mentira isto.

R

felipebonezi:
Também tive esta dúvida a muito tempo a atrás e pelo o que me disseram não tem como. Você teria que criar o componente! :frowning:

Mas espero que seja mentira isto.

esperamos…

mas valew mesmo assim.

R

UP

Eai pessoal? não tem como mesmo?

R

RESOLVIDO.

Galera, este datePicker pega a linguagem padrão do celular. O que eu estava testando estava em ingles. Testei em outro que estava em portugues e funcionou perfeitamente.

F

Bom saber carinha! :slight_smile:

Valeu pelo feedback.

K

Mesmo com um dispositivo que tenha linguagem inglês você pode alterar, basta setar o Locale para Pt-br. Pelo menos no emulador funciona.

R

Cara nao achei esta propriedade Locale nao.

Criado 14 de março de 2012
Ultima resposta 22 de mar. de 2012
Respostas 7
Participantes 3