gpt4 book ai didi

java - 使用 Xtend 进行 Android 开发(再次)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:52:41 27 4
gpt4 key购买 nike

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

  • 类型转换部分 (WebView)findViewById(R$id::webview) 给出未解析的 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>

想法?

最佳答案

1) Xtend 中的强制转换为“as”,在您的情况下 _webView = findViewById(R$id::webview) 作为 WebView

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

关于java - 使用 Xtend 进行 Android 开发(再次),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8854835/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com