How to use textview.getLayout()? It returns null

后端 未结 6 2009
孤独总比滥情好
孤独总比滥情好 2020-12-01 10:50

I’m trying set a layout for textview so I can use getEllipsisCount() method. But below code returns null as layout value. How can I take layout and

6条回答
  •  爱一瞬间的悲伤
    2020-12-01 11:30

    First, I do not know if it is a typo or it is intentional but you have declared a "settext" method instead of the predefined setText. However to get a reference of your layout I suggest you the following:

    LayoutInflater inflater = getLayoutInflater();
    
    RelativeLayout textViewLayout = (RelativeLayout) inflater.inflate(R.layout.activity_main,null);
    
    if (textViewLayout != null) {
        mytextview.setText("very good layout worked\n");
    }
    

    supposing that your TextView belongs to a RelativeLayout.

提交回复
热议问题