Using Xtend for Android Development (again)

I have 2 main points to get the following simple WebView example for compilation:

  • Cast part (WebView)findViewById(R$id::webview) gives unresolved JvmIdentifiableElement

  • Part of the anonymous class does not fully work. I suppose Xtend does not support it?

Here is the source code:

 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 } }) } } 

and my .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> 

Ideas?

+4
source share
1 answer

1) castings in Xtend are "how", in your case _webView = findViewById (R $ id :: webview) as WebView

2) Anonymous classes are not yet supported. Instead, use closure if the anonymous class only has one method (http://www.eclipse.org/Xtext/xtend/documentation/index.html#closures section on function mapping)

+5
source

Source: https://habr.com/ru/post/1390887/


All Articles