本文介绍了如何把结果从异步类mainActivity的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何访问

 保护无效onPostExecute(字符串结果){
        //结果
    }

这mainActivity?
i湾设置的EditText导致

 最后MainActivity mContext =新MainActivity();
的EditText showresult =(EditText上)mContext.findViewById(R.id.xx);

以上codeS不显示从mainActivity控制。

更新code

 保护无效onPostExecute(字符串结果){
        的EditText ED =(EditText上)findViewById(R.id.displayQue);
        ed.setText(结果);    }

解决方案

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. :)

这篇关于如何把结果从异步类mainActivity的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 11:37