Set Text View ellipsize and add view more at end

前端 未结 13 1175

I am trying to set ellipsize of text view. using the following code. I want to add \"view more\" at the end of truncated string after 3 dots. If this would be possible with

13条回答
  •  遥遥无期
    2020-12-02 13:17

    It might be late but its the easiest and tested way to handle this issue in recyclerview .

    first check the length of textview and set view more if require

    
    if (inventory.getDescription().length()>90) {
      inventoryDescription.setText(Html.fromHtml(inventory.getDescription().substring(0,90)+"..."+" View More"));
     }
     else inventoryDescription.setText(inventory.getDescription());
    
    

    and in textview click listener

    inventoryDescription.setOnClickListener(new View.OnClickListener() {
                @Override
        public void onClick(View v) {
    
       if (inventoryDescription.getText().toString().endsWith("View More")) {
           inventoryDescription.setText(inventory.getDescription());
          } 
        else {
    
       if (inventory.getDescription().length()>90) {
     inventoryDescription.setText(Html.fromHtml(inventory.getDescription().substring(0,90)+"..."+" View More"));
    
       }
       else inventoryDescription.setText(inventory.getDescription());
        }
    
                }
            });
    
    

提交回复
热议问题