Im building an android app, i have a web server based php page which returns data like
{"categories":[{"id":123,"name":"Category 1","img":""},{"id":12,"name":"Category 2","img":""},{"id":56,"name":"Category 2","img":""}]}
Now i have managed to use this data in java and get each element i need. Ive read a template file in that has code like:
<a class=button id="category_id"><img src="img_path"></img>category_name</a>
In Java i am doing string.replace on the contents of this template
content += template.replace("category_id", id).replace("category_name", name).replace("img_path", img_path);
This is being done in a for loop for each category and is now a string of value:
<a class=button id="123"><img src=""></img>Category 1</a><a class=button id="12"><img src=""></img>Category 2</a><a class=button id="56"><img src=""></img>Category 3</a>
Now this string when called in javascript like:
function showAndroidCategories() {
var html = Android.showCategories();
document.getElementById('.button-layout').innerHTML = html;
}
where .button-layout is a div on my webView. however i get this error:
"Uncaught TypeError: Cannot set property 'innerHTML' of null", source: file:///android_asset/www/index.html (32)
which refers to the last line of my javascript you can see above. All im trying to do is load a list of categories from the data and create a button for each one.
Thanks. Josh.