使用JSoup将HTML网站解析为Android Studio(片段)时,Android Studio t show an error and the AVD starts. But, I can
不会更改TextView的文本。
设置TextView的文本无效。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Website().execute();
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
// Title AsyncTask
private class Website extends AsyncTask<Void, Void, Void> {
String title;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
try {
// Connect to the web site
Document doc = Jsoup.connect("https://www.facebook.com/").get();
// Get the html document title
title = doc.title();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Set title into TextView
TextView txttitle = (TextView) getView().findViewById(R.id.titletxt);
txttitle.setText(title);
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}
我想在TextView“ titletxt”中显示网站的标题。
答案 0 :(得分:0)
最好在onImagePick(event: Event){
const file = (event.target as HTMLInputElement).files[0];
this.uploadForm.patchValue({ pdf : file });
this.uploadForm.get('pdf').updateValueAndValidity();
}
上执行任务
片段
该代码工作正常。或将用户代理设置为jsoup。可能会有帮助