textview.getLineCount always 0 in android

前端 未结 6 1563
执笔经年
执笔经年 2020-11-30 04:28

I\'m trying to dynamically resize my textview but getlinecount() method always returns me 0 even after settext() and invalidate(). I\'m using the following code:



        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 05:29

    I made an asynctask class and did my getLineCount()-related tasks in its onPostExecute method.

    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        new myAsyncTask().execute(null, null, null);
    }
    
    private class myAsyncTask extends AsyncTask {
    
        @Override
        protected Void doInBackground(final Void... params) {
            // It's okay to leave this as it is
            return null;
        }
    
        @Override
        protected void onPostExecute(final Void result) {
            super.onPostExecute(result);
            //DO YOUR TASK HERE, getLineCount(), etc.       
        }
    }
    

提交回复
热议问题