0
public class MyFragment extends Fragment implements OnClickListener {
EditText et;
Button submit;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
LinearLayout mLinearLayout = (LinearLayout) inflater.inflate(
R.layout.MyFragment, container, false);
et = (EditText) mLinearLayout.findViewById(R.id.etet);
submit = (Button) mLinearLayout.findViewById(R.id.bsubmit);
submit.setOnClickListener(this);
return mLinearLayout;
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bsubmit:
new processet().execute();
break;
}
}
private class processet extends AsyncTask<String, String, JSONObject> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected JSONObject doInBackground(String... args) {
String text = et.getText().toString();
UserFunctions userFunction = new UserFunctions();
JSONObject json = null;
Toast.makeText(getActivity(), text, Toast.LENGTH_LONG).show();
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
}
}
}
爲什麼這段代碼不工作? 我已檢查按鈕onClickListener工作正常.. 這只是一個簡單的代碼,我不知道它爲什麼不工作.. 我認爲必須有一些必要的更改,以便ASyncTask
可以在片段內工作..爲什麼我的asynctask不能在片段內工作?
移動'Toast.makeText(getActivity(),文本,Toast.LENGTH_LONG).show();''中onPostExecute' – Blackbelt
1)。發佈你的錯誤/例外2)。做什麼@Blackbelt說。 –