I have an ExpandaleList, and BaseExpandableListAdapter which I implements.
Now sometimes I need to show other xml content, So I am trying to do:
ExpandableList.this.setContentView(R.layout.errorscreen);
but then I get this exception:
ERROR/AndroidRuntime(23948): java.lang.RuntimeException, Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'.
Now, I have been told to do this in order to fix it:
add ExpandableListView to your xml layout and set it's id to list. Like so:
<ExpandableListView android:id="#id/android:list" android:layout_width="fill_parent"android:layout_height="fill_parent"/>
How to do it programmatically?
You are setting this Activity's contentView to a Layout which is defined in an xml file called errorscreen.xml:
ExpandableList.this.setContentView(R.layout.errorscreen);
The activity you're doing this from however extends ExpandableListActivity (I guess). Such an Activity needs an ExpandableListView in it's xml to display it's data. Now simply open your errorscreen.xml and add this element.
Cheers
Related
I have same kind of row value which are going to repeat in my activity multiple times so I have designed one row.xml for that and included required number of rows in my activity.xml by using include tag so if I want to change the value of the view which is there inside the row.xml file from activity.xml then how should we do that? I know that we can achieve this in Activity class and accessing it from activity but i want to deal this issue from xml only.
Thanks in advance.
I notice that there is a tag <view>(not <View>) which can be used in Android layout xml. When I add such a tag in a layout xml, the app can be successfully compiled but crashes when running. So what is this <view> used for?
view is an alternative way for specifying a view to inflate. You need to combine it with class attribute to specify the class name.
This is "useful" if your view class is an inner class and you cannot use something with a $ in the tag name in XML. (Having inner classes as Views you inflate is not a very good idea though.)
For example:
<view class="your.app.full.package.Something$InnerClass" ... />
Reference: http://androidxref.com/5.0.0_r2/xref/frameworks/base/core/java/android/view/LayoutInflater.java#696
View is widget of android that is use to add any kind of view.Like in problems when we use scrollView in a activity and at bottom of activity there is buttons ,That time we add view to looks better.We can set any kind of color to View .
for exp
This will make a View of 20dp height.
My main activity has a layout containing a ListView and several other items. I'd like to assign a ListAdapter to it. I followed the tutorials shown here: http://www.vogella.com/articles/AndroidListView/article.html
How can I let the adapter know that my activity's layout has a ListView in it, and assign it to it? When I try to run the app as-is it crashes with a runtime exception stating that my layout needs to have the default Android listview in it.
Thanks!
If your activity is inherited from ListActivity, you don't have to manually let the adapter know the ListView.
But in order to do this, ListView in your activity should look like this
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
because documentation says
your own view MUST contain a ListView object with the id "#android:id/list" (or list if it's in code)
When I try to run the app as-is it crashes with a runtime exception stating that my layout needs to have the default Android listview in it.
It sounds like you're using a ListActivity and calling setContentView(). In the layout that you pass to setContentView() you must have a ListView with the following attribute:
<ListView
android:id="#android:id/list"
... />
Then bind your Adapter to the ListView with setListAdapter().
I've got a ListView, which is fully defined in the xml file. Now I want to add a footer to thi s list so that the last element of the list became a button.
So firstly I do this: View v = getLayoutInflater().inflate(R.layout.add_new, null);, where add_new is the layout for my footer
Now I know that I need to do smth like this:
listViewInstance.addFooterView(v);
But i dont really have that instance as my ListView is defined in an xml file. So what do I write instead of listViewInstance? Is there a way to get its instance somehow from an xml?
Thanks in advance xxx
Use ListActivity.getListView() if you are using a ListActivity or Activity.findViewById() to get the reference to the list view otherwise.
Is there a way to link inherit class to xml file.
I am trying to connect extended class to widget in the xml file.
Is it possible ?
Thanks in advance.
You must have noticed that all the nodes that we specify in the layout XMLs are actually either View classes(for e.g: TextView, EditView) or view containers/layout managers(e.g: LinearLayout, RelativeLayout etc.). Android allows you to create custom views and containers by extending the View class and one of the layout managers, respectively. You can then choose to inflate such views directly from code or specify them as nodes in your layout XMLs.
For instance, assuming you create a View class such as:
public class com.views.MyView extends View{}
then you can include this class directly in you layout XML by saying:
<LinearLayout ..>
<com.views.MyView .. />
</LinearLayout>
Note that when you specify your View class directly in XML there are a few important subtleties to consider such as:
When inflating the custom view, the framework will call different constructor of the view. The arguments would be a context object and AttributeSet(containing attributes you set in the XML).
For more details refer this