我試圖在AsyncTask中的onPreExecute方法中更改文本視圖,但是我不斷收到空值點異常。任何幫助或替代品將不勝感激。在片段中更改TextView OnPreExecute
公共類FragmentOne擴展SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
new LongOperation().execute("");
View view = inflater.inflate(R.layout.fragmentone, container, false);
return view;
}
private class LongOperation extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
TextView txt = (TextView) getView().findViewById(R.id.textView1);
txt.setText("\nLoading...");
}
// etc etc etc
}
}
我試過了,它沒有工作。無論如何,謝謝你。 – user2122179
立即開始工作!也許因爲我把這個設置成view後new LongOperation()。execute(「」); – user2122179
祝你好運:D –