我不确定这是如何纠正的,但我收到一个错误说明:VISIBLE无法解析为变量。任何建议都非常感谢。到目前为止,我已经看过了:
http://developer.android.com/reference/android/view/View.html#setVisibility(int)
但我不明白在这种情况下如何实现这一点。
来源:
public class MainActivity extends Activity {
private TextView textView;
private String response;
public interface Callback {
void onModifiedTextView(String value);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.TextView01);
textView.setVisibility(VISIBLE);
}
public void onModifiedTextView(final String title) {
runOnUiThread(new Runnable() {
public void run() {
textView.setText(title);
textView.invalidate(); // not even necessary
}
});
}
public class DownloadWebPageTask extends AsyncTask<String, Void, String> {
public DownloadWebPageTask(MainActivity mainActivity) {
this.callback = mainActivity;
}
private MainActivity callback;
private String title;
public DownloadWebPageTask() {
// TODO Auto-generated constructor stub
}
public DownloadWebPageTask(TextView textView) {
// TODO Auto-generated constructor stub
}
@Override
protected String doInBackground(String... urls) {
String response = title;
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
Document doc = Jsoup.connect("http://google.com")
.userAgent("Mozilla")
.get();
// get page title
String title = doc.title();
System.out.println("title : " + title);
// get all links
Elements links = doc.select("a[href]");
for (Element link : links) {
// get the value from href attribute
System.out.println("\nlink : " + link.attr("href"));
System.out.println("text : " + link.text());
}
} catch (IOException e) {
e.printStackTrace();
}
}
// callback.onModifiedTextView(response);
return response;
}
@Override
protected void onPostExecute(final String title) {
callback.onModifiedTextView(title);
callback.onModifiedTextView(response);
}
}
public void onClick(View view) {
DownloadWebPageTask task = new DownloadWebPageTask(this);
task.execute(new String[] { "http://www.google.com" });
}
}
答案 0 :(得分:5)
VISIBLE
是View
类中的整数值。除非您在自定义视图中,否则应将其更改为View.VISIBLE
而不是VISIBLE
。
答案 1 :(得分:1)
除了@kcoppock的答案。你可以使用
您可以使用此导入:
import static android.view.View.VISIBLE;
或只是
textView.setVisibility(View.VISIBLE);
VISIBLE被定义为View class中的静态最终int。