0
我在Android中使用Json 1.9.2庫來解析網站中的數據,然後將結果數據設置爲Android中的TextView。但我無法在TextView上設置獲取的數據。來自Json查詢的數據未在Android Text View中填充
分享相關的代碼。我正在使用片段。
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
tv1 = (EditText) getActivity().findViewById(R.id.trending_textView);
new Title().execute();
}
private class Title extends AsyncTask<Void, Void, Void> {
String title;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setTitle("Fetching the latest trends");
mProgressDialog.setMessage("#Trends");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
public Void doInBackground(Void... params) {
try {
doc = Jsoup.connect(url).get();
Elements links = doc.getElementsByTag("a");
for (Element link : links) {
//String linkHref = link.attr("href");
linkText = link.text();
//System.out.println("#"+linkText);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
public void onPostExecute(Void result) {
tv1.setText(linkText.toString());
mProgressDialog.dismiss();
}
}
任何幫助將不勝感激。
是否'mProgressDialog.dismiss()'工作? – Zakir
'linkText'在'doInBackground'中打印什麼? – Zakir
我刪除循環後問題得到解決 – CodePlorer