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:
- Create an
interface
ResultListener with methodonResult(String result)
- Let MainActivity implement that interface
- Pass MainActivity as one parameter for the
AsyncTask
- Save the ResultListener as member for the
AsyncTask
- Trigger
onResult
inonPostExecute
for the ResultListener member - Show result got in
onResult
in yourEditText
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"