Ratwanska Ratwanska - 5 months ago 14
Android Question

how show buttons and elements after function loaded in android

It might be silly question but as I am new to android development hope some one will give a right suggestion and I hope wont get down votes for this.

I am having a webview and some textviews and buttons in my android app. First I am showing webview and continue button..

When clicking continue button, I am executing something in onClickListener from activity. In this function I am making visibility view.gone to webview and continue button and setVisibility view.visible to one editText and OK button.

For this editText I am showing value from continue button's onClickListener.

My problem is, editText and OK button are available immediately after clicking continue button. editText value is not available.

I want to stop the view of editText and OK button until value available and then I want to show editText..

How to do this in activity?

Answer

What Ankesh advised is right, here bit elaborated as per your need.

Put this code for your "continue" button's onClickListener,

continue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {               
    continue.setVisibility(View.GONE);   
    AsyncTaskRunner runner = new AsyncTaskRunner();
    runner.execute();

    }
});  

Also you need to add the following code to get the AsyncTask works..

private class AsyncTaskRunner extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
    try {
        // initiate your webview
        // call url in webview          
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "success";
}

@Override
protected void onPostExecute(String result) {
    ok.setVisibility(View.VISIBLE);
    editText.setVisibility(View.VISIBLE);
}

@Override
protected void onPreExecute() {
}

@Override
protected void onProgressUpdate(String... text) {
}
}

This should solves your problem.

For more info, take a look in the documentation,https://developer.android.com/reference/android/os/AsyncTask.html

Comments