pls help to solve problem

49 views
Skip to first unread message

nandu aeer

unread,
Feb 13, 2019, 11:07:09 PM2/13/19
to App Inventor Open Source Development
package com.nandu.Example; //package name of the extension


import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.*;
import com.google.appinventor.components.annotations.SimpleFunction;
import java.util.*;




import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.view.View;//
import android.view.LinearLayout .LayoutParams;// https://developer.android.com/reference/android/view/ViewGroup.LayoutParams
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.ComponentContainer;


@DesignerComponent(version = 1, 
                   description = ""
                   + "<a href='http://AppyBuilder.com' target='_blank'>http://AppyBuilder.com</a>",
                   category = ComponentCategory.EXTENSION,
                   nonVisible = true,
                   iconName = "aiwebres/icon.png") // "aiwebres/icon.png" Change your extension's icon from here; can be a direct url
@SimpleObject(external = true)
public class Example extends AndroidNonvisibleComponent implements Component {


public Context context;
         private ComponentContainer container;
        public Example(ComponentContainer container) {
        super(container.$form());
this.container = container;
context = (Context) container.$context();
  
  
  
  }
  
  
  @SimpleFunction(description=" adding items ")
  public void label(HVArrangement paramHVArrangement, String paramString1, int index)
  {
    ViewGroup layout = (ViewGroup)paramHVArrangement.getView();
 TextView tv = new TextView(this.context);
        tv.setText(paramString1);
tv.setId(index);
        tv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
     (( LinearLayout)linearLayout).addView(tv);
  
  }
}




Screenshot_20190125-080202


value is  placing them on top of each other:

nandu aeer

unread,
Feb 14, 2019, 8:44:02 PM2/14/19
to App Inventor Open Source Development
Pls help

Evan Patton

unread,
Feb 15, 2019, 8:21:30 AM2/15/19
to App Inventor Open Source Development
I think your issue is that you specify the width of the view to be MATCH_PARENT, but the horizontal/vertical arrangements will WRAP_CONTENT, so you have this juxtaposition where the parent wants to be as small as the children, and the children want to be as big as the parent. What happens if you set your LayoutParams to be WRAP_CONTENT on both dimensions?

Regards,
Evan

nandu aeer

unread,
Feb 15, 2019, 10:56:32 AM2/15/19
to App Inventor Open Source Development
same issue sir

nandu aeer

unread,
Feb 15, 2019, 11:00:21 AM2/15/19
to App Inventor Open Source Development
public void label(HVArrangement paramHVArrangement, String paramString1, int paramInt1)
{
ViewGroup layout = (ViewGroup)paramHVArrangement.getView();
TextView tv = new TextView(context);
tv.setText(paramString1);
tv.setId(paramInt1);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
layout.addView(tv,paramInt1);


}
}

nandu aeer

unread,
Feb 15, 2019, 11:03:08 AM2/15/19
to App Inventor Open Source Development
when i set wrap content for both diemension same error

Evan Patton

unread,
Feb 15, 2019, 12:14:44 PM2/15/19
to App Inventor Open Source Development
It might be worthwhile getting this first working in a simple project in Android Studio to understand how it works using the debugging facilities there. Once you know it works using the LinearLayout in Android Studio, you can backport the behavior to your App Inventor extension to determine whether or not it's an issue with how we handle LinearLayouts.

Regards,
Evan
Reply all
Reply to author
Forward
0 new messages