Skip to content Skip to sidebar Skip to footer

How To Put Result From Async Class To Mainactivity Edittext

how do i access protected void onPostExecute(String result) { //result } from mainActivity? i wan to set EditText to result final MainActivity mContext=new MainActiv

Solution 1:

read the stacktrace

E/AndroidRuntime(17146): java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText

it seems that you have an TextView in you layout xml but trying to use it as EditText in your code. that won't work. you either have to change the xml to use EditText or your code to use TextView

i assume that you only want to display the result so you should use the TextView (an EditText is a text input box where the user can type text)

you code should look like this

protectedvoidonPostExecute(String result) {
    TextView tv=(TextView)findViewById(R.id.displayQue);
    tv.setText(result);
}

good luck. :)

Solution 2:

Steps could be following:

  1. Create an interface ResultListener with method onResult(String result)
  2. Let MainActivity implement that interface
  3. Pass MainActivity as one parameter for the AsyncTask
  4. Save the ResultListener as member for the AsyncTask
  5. Trigger onResult in onPostExecute for the ResultListener member
  6. Show result got in onResult in your EditText

Solution 3:

You can use adapters to accomplish this.

Call your asynch method frompublic View getView(int position, View convertView, ViewGroup parent) method.

Post a Comment for "How To Put Result From Async Class To Mainactivity Edittext"