layout-inflater

Duplicate Views on Android during Run-time

廉价感情. 提交于 2019-12-03 20:15:55
问题 I have created a Layout file for an activity. In this layout I have created a LinearLayout with a textview and an edittext. Now I want to create additional LinearLayouts that will look and contain the exact same views that my original LinearLayout, but with different texts. I also want to do it programmatically during run because the amount of these LinearLayout will vary between runs. I've read some about inflaters but I don't understand them enough to use them. I'm thinking something like

Android: setContentView() == getViewInflate().inflate()?

浪尽此生 提交于 2019-12-03 18:27:19
I try my hardest to develop a clever way to clean out piles of Blah blah = (Blah) this.findViewById(R.id.blah) that otherwise pollute the field and the onCreate() method of my little Activity, and to do so, I feel I should not use setContentView() but getViewInflate().inflate() for every View defined in XMLs. Is Activity.setContentView() is sorta a syntax sugar and it's virtually repeating getViewInflate().inflate() for every View on XML? I read something saying as if they were the same. If I can get an answer by looking into the code, please tell so. I checked Activity.class, but only

What should I pass for root when inflating a layout to use for a MenuItem's ActionView?

北城余情 提交于 2019-12-03 06:30:28
问题 I have an ImageView that I attach to a MenuItem as its ActionView (the item appears in the ActionBar ). The layout for this view comes from XML. I'm inflating it like so: ImageView actionView = (ImageView) layoutInflater.inflate( R.layout.action_view_layout, null); This appears to work fine. However; passing null for root in the call to inflate() makes Lint yell at me: Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element) I can seemingly

fragments and onConfigurationChanged

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 03:25:10
I'm trying to do something I do with activities, but within a fragment. What I do is using activities: First stop the activity restarts when rotating the device android:configChanges="keyboardHidden|orientation|screenSize" in my activity add: @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); setContentView(R.layout.main); } So get the activity does not restart, but reloading the main.xml, to use the layout-land Now I have an activity showing viewpager, which contains three fragments. Everything works properly. Detection of the

What is the correct way to get layout inflater in Android?

我们两清 提交于 2019-12-03 02:42:10
问题 There is a way to get layoutInflater: LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); and another way is: LayoutInflater inflater = LayoutInflater.from(context); a third one (when I am in an Activity) is: LayoutInflater inflater = getLayoutInflater(); So what is the difference between them? Note that when I sent the third inflater to my adapter, my application worked. But when I sent the context and created the inflater via the second way,

What should I pass for root when inflating a layout to use for a MenuItem's ActionView?

青春壹個敷衍的年華 提交于 2019-12-02 20:06:45
I have an ImageView that I attach to a MenuItem as its ActionView (the item appears in the ActionBar ). The layout for this view comes from XML. I'm inflating it like so: ImageView actionView = (ImageView) layoutInflater.inflate( R.layout.action_view_layout, null); This appears to work fine. However; passing null for root in the call to inflate() makes Lint yell at me: Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element) I can seemingly manage without a root in my specific case, but I'd rather have the code be as correct as possible. The

What is the correct way to get layout inflater in Android?

ぃ、小莉子 提交于 2019-12-02 16:15:38
There is a way to get layoutInflater: LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); and another way is: LayoutInflater inflater = LayoutInflater.from(context); a third one (when I am in an Activity) is: LayoutInflater inflater = getLayoutInflater(); So what is the difference between them? Note that when I sent the third inflater to my adapter, my application worked. But when I sent the context and created the inflater via the second way, it didn't! There is not much of a difference between them. As doc says public abstract Object

Why does the XML onClick attribute set an OnClickListener TWICE on AppCompatButtons

点点圈 提交于 2019-12-02 08:52:45
When Android inflates a Button with an onClick XML attribute, it internally sets a DeclaredOnClickListener on that Button which then uses reflection to trigger the actually onClick method in our code. case R.styleable.View_onClick: [...] final String handlerName = a.getString(attr); if (handlerName != null) { setOnClickListener(new DeclaredOnClickListener(this, handlerName)); } break; I noticed that for AppCompatButton s (i.e. normal Buttons in an AppCompatActivity ) the same process gets repeated in the AppCompatViewInflater class, resulting in 2 different DeclaredOnClickListener s set in

Parent Activity's code getting executed, but the result (animation) is not showing up

跟風遠走 提交于 2019-12-02 08:27:55
I want to have a sliding menu throughout my application which will be accessible for every activity in my application. For this, I created a parent activity to which all other activities extend as suggested in this answer . So that, only one activity will implement that sliding menu functionality and all other activities extending that activity will have that implementation. But my problem is, when I press UP button (app icon) the sliding drawer should show up and the whole layout should shift to the right side. This works fine for the BaseActivity, but for the activities extending that class,

How to inflate another xml on clicking a button

霸气de小男生 提交于 2019-12-02 08:07:05
问题 I have one Activity in that there are no Button s but I have coded it in such a way that another Activity comes, now in this second Activity there are three Button s, on which when I click all inflating different respective activities. In this second Activity there I have added one more Button , on clicking this 4th Button I don't want another Activity to come in foreground instead i just want another layout to be inflated(I don't wanna change the Activity ) In that layout(which i need to