I have developed an application where i am using the same textview again and again so i need to clear textview very frequently.
Since it is related to UI i have to perform this task on UI thread but it takes 5-6 milliseconds to clear the textview only which seems very huge i guess. Can anybody help me to reduce this time so i can manage my UI task very smoothly without skipping any frames?
I am attaching my code snippet for a reference where i have tried two methods but the least time was 5 milliseconds.
public class MainActivity extends AppCompatActivity { EditText editText; Button btnClearText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); editText = findViewById(R.id.editText); btnClearText = findViewById(R.id.btnClearText); btnClearText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // test with empty text editText.setText(""); // try with setText(''); Log.e("clearText", "setText(''): start "+ new Date().getTime()); editText.setText(""); Log.e("clearText", "setText(''): end" + new Date().getTime()); // difference of 15 millisecond // try with getText().clear(); Log.e("clearText", "getText().clear(): start" + new Date().getTime()); editText.getText().clear(); Log.e("clearText", "getText().clear(): end" + new Date().getTime()); // difference of 5 millisecond } }); } }
Any suggestions or alternate methods to improve performance?
Thanks,