Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

okhttp Updating Views on UIThread

client.newCall(request).enqueue(new Callback() {
    @Override
    public void onResponse(Call call, final Response response) throws IOException {
        // ... check for failure using `isSuccessful` before proceeding

        // Read data on the worker thread
        final String responseData = response.body().string();

        // Run view-related code back on the main thread
        MainActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    TextView myTextView = (TextView) findViewById(R.id.myTextView);
                    myTextView.setText(responseData);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
       }
    }
});
Comment

PREVIOUS NEXT
Code Example
Java :: Java Default Access Modifier package one 
Java :: iterator java8 
Java :: remove character stringbuffer 
Java :: polymorphism array with abstract class java 
Java :: java resultset to object 
Java :: pack in swing 
Java :: jframe centerlaized 
Java :: java try-with-resources nested streams 
Java :: inheritance setter and getter in java 
Java :: Set value of input in android webview 
Java :: string equlity 
Java :: data validation dialog box android 
Java :: use flatpickr in javascripot 
Java :: javax.servlet.Filter 
Java :: how-to-use-volley-string-request-in-android 
Java :: setvisibility not working in fragment 
Java :: editable java jcombobox 
Java :: spring import properties file xml 
Java :: Java Create a FileOutputStream 
Java :: copy array of objects in java 
Java :: light black border android 
Java :: how to decode a ByteArray to Bitman in adroid 
Java :: java png obj animate image size 
Java :: dynamic fib 
Java :: licenceurl 
Java :: ggt euklidischer algorithmus java 
Java :: java notnull returns null 
Java :: java get if contains else 0 
Java :: how to implement count steps in android 
Java :: priority queue is empty java 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =