Show first letter textview

Asked

Viewed 166 times

0

I’m taking the Firebase data and putting it into a Reciclerview. And I’m using the Textdrawable library to display the first letter of the text naming in a circle made the gmail app.However I cannot take the first letter and show in the circle always comes empty.

public class SecaoViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

public TextView nomeSecao;
ImageView imageView50;


private ItemClickListener itemClickListener;

public void setItemClickListener(ItemClickListener itemClickListener) {
    this.itemClickListener = itemClickListener;
}

public SecaoViewHolder(View itemView) {
    super(itemView);

    nomeSecao = (TextView) itemView.findViewById(R.id.secao_nome);
    imageView50 = (ImageView) itemView.findViewById(R.id.image_view50);


    String primeiraLetra = nomeSecao.getText().toString().substring(0, 1);

        ColorGenerator generator = ColorGenerator.MATERIAL;
        int color = generator.getRandomColor();
        TextDrawable drawable = TextDrawable.builder()
                .buildRound(primeiraLetra, color);


        imageView50.setImageDrawable(drawable);

    itemView.setOnClickListener(this);
}



@Override
public void onClick(View view) {
    itemClickListener.OnClick(view,getAdapterPosition(),false);
}

}

//Carrega o recycleview da Seção com os dados do Firebase
private void loadListSecao(String organizacaoId) {
    adapter = new FirebaseRecyclerAdapter<Secao, SecaoViewHolder>(
            Secao.class,
            R.layout.secao_item,
            SecaoViewHolder.class,
            secaoList.orderByChild("organizacaoId").equalTo(organizacaoId)
    ) {
        @Override
        protected void populateViewHolder(SecaoViewHolder viewHolder, Secao model, int position) {
            viewHolder.nomeSecao.setText(model.getNomeSecao());

            final Secao local = model;

        }
    };

    recyclerView.setAdapter(adapter);
}
  • Try String primeiraLetra = nomeSecao.getText().toString().charAt(0)+"";

  • It didn’t work. Caused by: java.lang.Stringindexoutofboundsexception: length=0; index=0

  • Then Textview is empty, insert the text you want into it

  • How can I add the text to the nameThere class? I’ve tried several modes and I couldn’t.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.