I am trying to create a custom statusbar notification layout with java instead of xml. I created a linearlayout, set the required parameters, set it in the notification remoteview, but its giving me FCs. (“Bad notification posted”)
Here is my test code:
LinearLayout layoutTest;
layoutTest = new LinearLayout(this);
layoutTest.setOrientation(LinearLayout.VERTICAL);
LayoutParams paramTest = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT, 1.0f);
layoutTest.setLayoutParams(paramTest);
layoutTest.setId(R.id.mlinearlayout);
contentView = new RemoteViews(this.getPackageName(), R.id.mlinearlayout);
nbuilder.setContent(contentView);
// and all the other notification builder good stuff
I am not really familiar with setId(), can that be the problem?
For the id i created /res/values/ids.xml with:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="mlinearlayout" />
</resources>
Any help would be greatly appreciated!
It’s probably related with that
RemoteViewscontructor is expecting the identifier of an XML file, and you’re passing the identifier of an element.Maybe it gives you some more insight looking in the source of RemoteView’s methods like
public View apply(Context context, ViewGroup parent)where the view is inflated, using the layout id.Do you really have to do it programmatically? XML seems to be the way to go, it’s at least the documented one, and I don’t see the reson in your code, why you need to do it programmatically.