For some reason, Eclipse doesn't like the call to super(context, attrs, defStyle), yet it's happy with the other super calls. The error is "The constructor LinearLayout(Context, AttributeSet, int) is undefined".
I don't think the problem is with this code itself, but something else in the project's settings or something, since I adapted almost identical code from an example that did the same thing but for a RelativeLayout, which ran fine on my Eclipse setup in a test project.
Please Help :)
public class MyLinearLayout extends LinearLayout {
public MyLinearLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
myInit();
}
public MyLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
myInit();
}
public MyLinearLayout(Context context, int checkableId) {
super(context);
myInit();
}
According to these javadocs the error is completely correct.
LinearLayout does not have that constructor. These are the two valid constructors:
LinearLayout(Context context)
LinearLayout(Context context, AttributeSet attrs, Map inflateParams)
http://developer.android.com/reference/android/widget/LinearLayout.html
According to the developer site, the LinearLayout(context, attrs, defStyle) constructor is only available in API version 11, so it won't work in earlier versions.
Related
We have an old custom navigation bar in our tablet code that I am trying to convert to Jetpack Compose.
I have the scaffold set up and it appears on the app. I'm now trying to use the stored resources to display them on my new navigation bar.
The problem is that I can't seem to reference any of these resources when they come from the StyledAttributes.
For example, I am just trying to get the string for the Title of the app to appear and here is the existing code (that will eventually be replaced):
NavigationBar
public class NavigationBar extends RelativeLayout {
...
public NavigationBar(Context context) {
this(context, null, R.attr.navigationBarStyle);
}
public NavigationBar(Context context, AttributeSet attrs) {
this(new ContextThemeWrapper(context, R.style.Material_ActionBar_Light), attrs, R.attr.navigationBarStyle);
}
public NavigationBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = this.getContext().obtainStyledAttributes(attrs, R.styleable.NavigationBar, defStyle, 0);
Drawable iconId = a.getDrawable(R.styleable.NavigationBar_navIcon);
String title = a.getString(R.styleable.NavigationBar_navTitle);
a.recycle();
init(context, iconId, title);
}
...
Is there a good way to reference the Styled Attributes to obtain the icons and strings?
It's especially tricky when using this to reference the NavigationBar because the NavigationBar is the part I'm trying to get rid of.
I am implementing the library provided by etsy on github for StaggeredGrid https://github.com/etsy/AndroidStaggeredGrid . The error i am getting is InflationException for the layout activity_svg.xml
<com.etsy.android.grid.StaggeredGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:item_margin="8dp"
app:column_count="#integer/grid_column_count" />
android.view.InflationException Binary XML File Line#3 Error inflating class com.etsy.android.grid.StaggeredGridView
As per previous answers related to the question i have checked the constructors :
public StaggeredGridView(final Context context) {
this(context, null);
}
public StaggeredGridView(final Context context, final AttributeSet attrs) {
this(context, attrs, 0);
}
public StaggeredGridView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
As per previous answer i have also checked whether the file lies in this library or not.
So what else can be the problem for InflationException ? Why is the class not getting inflated?
If you want me to add any more part of the code please comment.
If you have custom controls in your application then it should be specified using the full package in your layout XML, if only "yourcustomcontrol" is used it will throw this error. For example:
<yourcustomcontrol android:id="#+id/yourCustomControl1" /> will throw error.
<packageName.yourcustomcontrol android:id="#+id/yourCustomControl1" />
will work.
More about custom controls can be found at the android developers' homepage here
Originally answered here.
I got a class to extend NumberPicker component to introduce min & max value:
public class ExtendedNumberPicker extends NumberPicker {
public ExtendedNumberPicker(Context context) {
super(context);
}
public ExtendedNumberPicker(Context context, AttributeSet attrs) {
super(context, attrs);
processAttributeSet(attrs);
}
public ExtendedNumberPicker(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
processAttributeSet(attrs);
}
private void processAttributeSet(AttributeSet attrs) {
//This method reads the parameters given in the xml file and sets the properties according to it
this.setMinValue(attrs.getAttributeIntValue(null, "min", 0));
this.setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
}
}
I put it into layout:
<com.example.myapp.component.ExtendedNumberPicker
android:id="#+id/pick_hh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="16dp"
min="140"
max="200" />
In LogCat, it shows:
Tag Text
---------------------------
PropertyValuesHolder Can't find native method using JNI, use reflectionjava.lang.NoSuchMethodError: no method with name='setSelectorPaintAlpha' signature='(I)V' in class Lcom/example/myapp/component/ExtendedNumberPicker;
PropertyValuesHolder Couldn't find setter/getter for property selectorPaintAlpha with value type int
I know JNI is Java Native Interface, but I never use/see the property selectorPaintAlpha. What is it? How to resolve the issue?
I am new to android and would like some assistance on rotating my relative layout for a two-player game I am working on. I have seen the posts here and have looked into many other posts on the same subject on SO. My first question is how to I call the new class I just made? For all the posts that dont just tell me to use android:rotation (which is not avaliable in 2.3-) I make a new class, but I get a notification that the class is never called. Do I call the class simmilar to how I call a method? Or is there some command in AndroidManifest? Finialy, how does the new class rotate only one Relative layout and not the other? I just would like to know how its supposted to work.
This is the new Class that I am supposted to make:
public class MyRelativeLayout extends RelativeLayout {
public MyRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyRelativeLayout(Context context) {
super(context);
init();
}
private void init() {
setStaticTransformationsEnabled(true);
}
#Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
t.setTransformationType(Transformation.TYPE_MATRIX);
Matrix m = t.getMatrix();
m.reset();
m.postRotate(180, child.getWidth() / 2.0f, child.getHeight() / 2.0f);
return true;
Thanks for your help
In the oncreate() method in your activity do setContentView(new MyRelativeLayout(this))
I need to show Hindi and Bengali font support in my app. How to do this.Please help.
Also tell me how can I get the support from XML, as I need to get the data through web-services.
What I did is that is put a particular font of choice to assets folder and used this code:
public class CustomTextView extends TextView{
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initFont();
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
initFont();
}
public CustomTextView(Context context) {
super(context);
initFont();
}
private void initFont() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),"myfont.ttf");
setTypeface(tf);
}
}
But the problem what I am facing is that the even if I am getting the fonts in my emulator some of the fonts patterns are not correct.
Reply if anybody wants to add more to my answer, you are welcome.