| Template code | Chunk output | |
|---|---|---|
{#example_1}
{!-- Chunk can grab templates right from the classpath on
-- the enterprise, but in Android things are a bit different.
--
-- Place templates in assets/themes/*.chtml and use
-- com.x5.template.provider.AndroidTemplates to load
-- them from there into your Theme. v2.4 and up.
--
--}
See Java tab for example code.
{#}
import com.x5.template.Chunk;
import com.x5.template.Theme;
import com.x5.template.providers.AndroidTemplates;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class HelloAndroidActivity extends Activity
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// You wouldn't want to initialize the Theme
// over and over like this, just trying to
// keep the example simple.
AndroidTemplates loader = new AndroidTemplates(getBaseContext());
Theme theme = new Theme(loader);
Chunk chunk = theme.makeChunk("test#subtest");
Toast.makeText(HelloAndroidActivity.this, chunk.toString(), Toast.LENGTH_SHORT).show();
}
});
}
}
|
|
See Java tab for example code.
See Java tab for example code.
|
| Template code | Chunk output | |
|---|---|---|
{#example_2}
Loading HTML into an Android WebView - see Java tab.
{#}
// how to use a string of HTML as the source of a WebView String html = chunk.toString(); String mime = "text/html"; String encoding = "utf-8"; WebView myWebView = (WebView)this.findViewById(R.id.myWebView); myWebView.getSettings().setJavaScriptEnabled(true); // If you want to reference images from your assets folder, // use baseURL = "file:///android_res/raw/" instead of null here. String baseURL = null; myWebView.loadDataWithBaseURL(baseURL, html, mime, encoding, null); |
|
Loading HTML into an Android WebView - see Java tab.
Loading HTML into an Android WebView - see Java tab.
|