“CustomAdapter” ListView Customview example
Little changes DroidScript page’s code(http://droidscript.blogspot.jp/2010/03/custom-listadapter-in-using-java-proxy.html)
It’s working. This example, ListView item contains layouted three TextView.
I’m using it as RSS widget replacement with Tasker.
(2015/06/29 edit this post)
LL.bindClass(“java.util.HashMap”);
LL.bindClass(“java.util.ArrayList”);
LL.bindClass(“android.view.View”);
LL.bindClass(“android.view.Gravity”);
LL.bindClass(“android.widget.ListAdapter”);
LL.bindClass(“android.widget.ListView”);
LL.bindClass(“android.widget.LinearLayout”);
LL.bindClass(“android.widget.TextView”);
LL.bindClass(“java.lang.reflect.Array”);
LL.bindClass(“java.lang.reflect.Proxy”);
LL.bindClass(“java.lang.Class”);
LL.bindClass(“java.lang.ClassLoader”);
LL.bindClass(“java.lang.String”);
LL.bindClass(“java.lang.Boolean”);
LL.bindClass(“java.lang.Integer”);
LL.bindClass(“java.lang.Long”);
LL.bindClass(“java.lang.Double”);
LL.bindClass(“java.lang.Number”);
retDataList = new ArrayList(LL.getContext());
for (n=0; n<20; n++) {
retDataList.add({
title:”Lightning Launcher”,
description:”ListView CustomAdapter test. ListView CustomAdapter test. ListView CustomAdapter test.”,
date:”24:00″,
});
}
item.setVerticalGrab(true);
var context = LL.getContext();
var listView = new ListView(context);
listView.setBackgroundColor(Color.parseColor(“#ff222222”));
listView.setDivider(new ColorDrawable(Color.parseColor(“#ffeeeeee”)));
listView.setDividerHeight(1);
listView.setPadding(16,8,16,8);
var adapter = createListViewArrayAdapter(
retDataList,
function(position, convertView)
{
var view1 = convertView;
var view2;
var text1;
var text2;
var text3;
var text1text = retDataList.get(position).title;
var text2text = retDataList.get(position).description;
var text3text = retDataList.get(position).date;
if (null == view1) {
view1 = new LinearLayout(context);
view1.setOrientation(LinearLayout.HORIZONTAL);
view1.setLayoutParams(LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));
view1.setPadding(8,8,8,8);
view2 = new LinearLayout(context);
view2.setOrientation(LinearLayout.VERTICAL);
view2.setLayoutParams(LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT,1));
view2.setPadding(0,0,0,0);
view1.addView(view2);
text1 = new TextView(context);
text1.setId(01);
text1.setTextColor(Color.parseColor(“#ffeeeeee”));
text1.setTextSize(15);
text1.setTypeface(Typeface.SERIF,Typeface.BOLD);
text1.setLayoutParams(LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT,0));
text1.setText(text1text);
view2.addView(text1);
text2 = new TextView(context);
text2.setId(02);
text2.setTextColor(Color.parseColor(“#ffeeeeee”));
text2.setTextSize(13);
text2.setTypeface(Typeface.SANS_SERIF,Typeface.ITALIC);
text2.setLayoutParams(LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT,0));
text2.setText(text2text);
view2.addView(text2);
text3 = new TextView(context);
text3.setId(03);
text3.setTextColor(Color.parseColor(“#ffeeeeee”));
text3.setTextSize(11);
text3.setTypeface(Typeface.MONOSPACE,Typeface.NORMAL);
text3.setGravity(Gravity.RIGHT);
text3.setLayoutParams(LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT,0));
text3.setText(text3text);
view1.addView(text3);
}
else if (null != view1) {
text1=TextView(convertView.findViewById(01));
text1.setText(text1text);
text2=TextView(convertView.findViewById(02));
text2.setText(text2text);
text3=TextView(convertView.findViewById(03));
text3.setText(text3text);
}
return view1;
});
listView.setAdapter(adapter);
return listView;
function javaArrayToJsArray(javaArray)
{
var jsArray = [];
for (i = 0; i < javaArray.length; ++i) {
jsArray[i] = javaArray[i];
}
return jsArray;
}
function createInstance(javaInterface, handler)
{
var interfaces = Array.newInstance(Class, 1);
interfaces[0] = javaInterface;
var obj = Proxy.newProxyInstance(
ClassLoader.getSystemClassLoader(),
interfaces,
function(proxy, method, args) {
return handler[method.getName()].apply(
null,
javaArrayToJsArray(args)
);
});
return obj;
}
function createListViewArrayAdapter(items, viewFun)
{
var observer;
var handler = {
areAllItemsEnabled : function() {
return true; },
isEnabled : function(position) {
return true; },
getCount : function() {
return new Integer(items.size()); },
getItem : function(position) {
return new String(items.get(position)); },
getItemId : function(position) {
return new Long(position); },
getItemViewType : function(position) {
return new Integer(0); },
getView : function(position, convertView, parent) {
return viewFun(position, convertView); },
getViewTypeCount : function(position) {
return new Integer(1); },
hasStableIds : function(position) {
return true; },
isEmpty : function(position) {
return 0 == items.size(); },
registerDataSetObserver : function(theObserver) {
observer = theObserver; },
unregisterDataSetObserver : function(theObserver) {
observer = null; },
};
return createInstance(ListAdapter, handler);
}
]]>
< ![CDATA[
Thanks for sharing.
What has to be done on the Tasker side?
Could be helpful to provide a little tutorial. I am sure many would appreciate a ‘LL rss widget how to’ (me included).
What do you think?
]]>
< ![CDATA[
Definitely would love a pure LL RSS widget!๐๐
]]>
< ![CDATA[
Thomas Greer patience, it can be done. Simular to how my weather-agenda is done. patience.
]]>
< ![CDATA[
Jappie Toutenhoofd that’s kind of what I figured, but I didn’t want to show how ignorance! ๐
]]>
< ![CDATA[
anyone got this work? would appreciate more details on how to setup, screenshots, etc.
]]>
< ![CDATA[
Sorry,
After I tried it again, Sample might does not work.
It worked by adding one line in the beginning lines of code(I edited first post too).
LL.bindClass(“android.view.Gravity”);
I hope that this sample works like a screenshot.
I posted this code that Customadapter is important. And, RSSview is not yet complete …
]]>