开发者

Android: Inflate listview using its android:id [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question 开发者_如何学Goso that it can be reopened, visit the help center. Closed 11 years ago.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜