importPackage(androidx.recyclerview.widget);
importPackage(android.widget)
let recyclerView = new RecyclerView(context);
layoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(layoutManager);
var activity = ui.getActivity();
ui.logd("activity " + activity);
activity.setContentView(recyclerView);
ui.logd("activity22 " + activity);
for (var i = 0; i < 10; i++) {
giftBoxList.push(new GiftBox(i + "个", i * 2 + "斤", i * 3 + "袋"));
ui.logd("giftBoxList " + giftBoxList);
let recycleAdapter = createGiftBoxAdapter(giftBoxList);
ui.logd("recycleAdapter " + recycleAdapter);
recyclerView.setAdapter(recycleAdapter);
function createGiftBoxAdapter(giftBoxList) {
return RecyclerView.Adapter({
onCreateViewHolder: function (parent, viewType) {
view = new TextView(context);
holder = JavaAdapter(RecyclerView.ViewHolder, {},
onBindViewHolder: function (holder, position) {
giftBox = giftBoxList[position];
holder.itemView.setText(giftBox.getLollipops());
ui.logd("giftBox " + giftBox)
getItemCount: function () {
return giftBoxList.length;
function GiftBox(lollipops, melonSeeds, peanut) {
this.lollipops = lollipops;
this.melonSeeds = melonSeeds;
GiftBox.prototype.getLollipops = function () {
GiftBox.prototype.getMelonSeeds = function () {
GiftBox.prototype.getPeanut = function () {
GiftBox.prototype.getGiftType = function () {