I don't know if this is possible, is it possible for me to inflate a listview using only its id? Thanks.
I think you may be confused about the difference between a component ID and a layout ID.
A layout ID refers to the name of a layout XML file. For example, if you have a layout named res/layout/home_activity.xml
, its ID would be stored as R.layout.home_activity
.
A component ID refers to the identity of a UI component inside an existing layout. So, inside your home_activity.xml
layout you might have <TextView android:id="@+id/my_textview" />
. The ID of that View is R.id.my_textview
.
You can only inflate layouts using a layout ID. 'Inflating' a component ID doesn't make any sense, unless you inflate a layout as a child of a View with a specific ID.
Now that things are more clear, I suggest that you set your 'Inflatable ListView' as gone
in your Layout file using:
<ListView android:visibility="gone" ... />
Then just set it to visible using View.setVisibility()
whenever you want it to 'inflate'
mHiddenListView.setVisibility(View.VISIBLE);
Yes, the layout inflater inflates any View from the Resource id.
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
listView = inflater.inflate(R.id.your_listview, parentView );
Edit: Well, it has to be a layout ID referring to some xml layout, not a component of it. Why don't you create a new xml containing that view component that you want to extract?
精彩评论