Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamically update TextView in Android

I am quite new to Android development. Can someone let me know the relevant APIs to dynamically update a TextView (or entire screen )?

For example: I have a search application and I need to show the results as they are found rather than waiting for all results and then show.

like image 382
prash Avatar asked Feb 02 '11 10:02

prash


2 Answers

There are a few steps and you didn't mention how much you know versus how much you don't.

Assuming your UI initial structure is defined in the res/layout and it includes a TextView somewhere, in your activity:

public void updateTextView(String toThis) {
    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText(toThis);
}
like image 199
Frank C. Avatar answered Sep 28 '22 07:09

Frank C.


Try this one

TextView textView = (TextView)findViewById(R.id.textViewID);
textView.setText("The test you need");
view.invalidate();  // for refreshment
like image 39
Roushdy Avatar answered Sep 28 '22 08:09

Roushdy