0

我不确定如何纠正这种情况,但我收到一条错误消息: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" });
    }
}
4

2 回答 2

5

VISIBLEView类中的整数值。除非您在自定义视图中,否则您应该将其更改为View.VISIBLE而不是 just 。VISIBLE

于 2013-09-11T21:53:26.720 回答
1

除了@kcoppock 答案。您可以使用

您可以使用此导入:

 import static android.view.View.VISIBLE;

要不就

textView.setVisibility(View.VISIBLE);

VISIBLE 在View 类中被定义为 static final int 。

于 2013-09-11T21:58:01.290 回答