Search code examples
androidtextviewandroid-scrollview

Scrolling textview on progress update


I have an asynctask that reads data from a device and then I want to show this data in a TextView. I have a ScrollView in my application, and have a TextView inside it, textview is manually scrolling but I need to update the position of the last line on update progress, here is my Asynctask code

private class ReadDataTask extends AsyncTask<Void, String, String>{

        /* (non-Javadoc)
     * @see android.os.AsyncTask#onProgressUpdate(Progress[])
     */
    @Override
    protected void onProgressUpdate(String... values) {
        String frm=values[0];
        Log.d("bluetoothdata", frm);
        if(logtextview.getText().length()>(1024*1024)){
            logtextview.setText(frm);
        }else{
            logtextview.append(frm);
        }

    //  Toast.makeText(SetBluetoothActivity.this, "frame updated", Toast.LENGTH_SHORT).show();
    }

        @Override
        protected String doInBackground(Void... params) {

            while(connected){
                String frame=readFrame();
                publishProgress(frame);
            }
            return null;
        }

    }

What I need is to position my textview as its last line will always appear. Any help will be appreciated


Solution

  • Have you tried the solutions listed here?

    auto-scrolling TextView in android to bring text into view

    Android: auto scrolling down the EditTextView for chat apps

    how to implement Scroller in textview for auto scrolling?