vbCoder vbCoder - 5 months ago 14
Android Question

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 MainActivity();
EditText showresult=(EditText)mContext.findViewById(R.id.xx);


above codes does not show the control from mainActivity.

updated code

protected void onPostExecute(String result) {
EditText ed=(EditText)findViewById(R.id.displayQue);
ed.setText(result);

}





09-03 15:31:19.882: D/AndroidRuntime(17146): Shutting down VM
09-03 15:31:19.882: W/dalvikvm(17146): threadid=1: thread exiting with uncaught exception (group=0x40d45930)
09-03 15:31:19.992: E/AndroidRuntime(17146): FATAL EXCEPTION: main
09-03 15:31:19.992: E/AndroidRuntime(17146): java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
09-03 15:31:19.992: E/AndroidRuntime(17146): at com.example.digiqueue.MainActivity$ftpfunctions.onPostExecute(MainActivity.java:106)
09-03 15:31:19.992: E/AndroidRuntime(17146): at com.example.digiqueue.MainActivity$ftpfunctions.onPostExecute(MainActivity.java:1)
09-03 15:31:19.992: E/AndroidRuntime(17146): at android.os.AsyncTask.finish(AsyncTask.java:631)
09-03 15:31:19.992: E/AndroidRuntime(17146): at android.os.AsyncTask.access$600(AsyncTask.java:177)
09-03 15:31:19.992: E/AndroidRuntime(17146): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
09-03 15:31:19.992: E/AndroidRuntime(17146): at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 15:31:19.992: E/AndroidRuntime(17146): at android.os.Looper.loop(Looper.java:176)
09-03 15:31:19.992: E/AndroidRuntime(17146): at android.app.ActivityThread.main(ActivityThread.java:5365)
09-03 15:31:19.992: E/AndroidRuntime(17146): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 15:31:19.992: E/AndroidRuntime(17146): at java.lang.reflect.Method.invoke(Method.java:511)
09-03 15:31:19.992: E/AndroidRuntime(17146): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
09-03 15:31:19.992: E/AndroidRuntime(17146): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
09-03 15:31:19.992: E/AndroidRuntime(17146): at dalvik.system.NativeStart.main(Native Method)

Answer

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

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

good luck. :)

Comments