4

我有 2 个主要症结来编译以下简单的 WebView 示例:

  • 铸件(WebView)findViewById(R$id::webview)unresolved JvmIdentifiableElement

  • 匿名类部分完全不起作用。我想Xtend不支持它?

这是源代码:

package com.stackoverflow

import android.app.Activity
import android.webkit.WebView
import android.os.Bundle
import android.webkit.WebViewClient

class HelloWebViewActivity extends Activity
{
    WebView _webView

    override void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState)
        setContentView(R$layout::main)

        // Error "Couldn't resolve reference to JvmIdentifiableElement 'WebView'"
        _webView = (WebView)findViewById(R$id::webview)
        _webView.settings.javaScriptEnabled = true
        _webView.loadUrl("http://stackoverflow.com")

        // A bunch of complaints towards the anonymous class
        _webView.setWebViewClient(new WebViewClient()
        {
            override shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url)
                true
            }
        })
    }
}

我的.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="xtend-gen"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins" />
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="con" path="org.eclipse.xtend.XTEND_CONTAINER"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

想法?

4

1 回答 1

5

1) Xtend 中的演员表是' as ',在你的情况下 _webView = findViewById(R$id::webview) as WebView

2) 尚不支持匿名类。如果匿名类只有一个方法,请考虑使用闭包(http://www.eclipse.org/Xtext/xtend/documentation/index.html#closures 函数映射部分)

于 2012-01-14T07:21:42.787 回答