安卓入门查看加入LayoutInflator [英] Android: Getting the View added with LayoutInflator

查看:146
本文介绍了安卓入门查看加入LayoutInflator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java或C#的答案都很好(我们使用MonoDroid的)

Java or C# answers are fine (we use MonoDroid)

我控制成功添加到LinearLayout中有:

I successfully add a control to a LinearLayout with:

    LayoutInflater _inflatorservice = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
    var viewContainer = _inflatorservice.Inflate(Resource.Layout.ReportItImageButton, myLinearLayout);

我如何再获取到视图的引用刚才添加?我增加了许多相同的控制,这种方式使需要得到的第n项添加到布局。

How do I then get a reference to the view just added? I add many of the same control this way so would need to get the nth item added to the layout.

推荐答案

这个工作,它得到最新的产品加入假设产品类型的按钮。

This works, it gets the most recent item added assuming the item is of type Button.

        LayoutInflater _inflatorservice = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
        var layout = _inflatorservice.Inflate(Resource.Layout.ReportItImageButton, layoutImages) as LinearLayout;

        if (layout != null)
        {
            var b = layout.GetChildAt(layout.ChildCount - 1) as Button;
            if (b != null)
            {

            }
        }

这篇关于安卓入门查看加入LayoutInflator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆