简单的 LayoutInflater 不更新视图

发布于 2024-11-18 14:18:24 字数 2113 浏览 7 评论 0原文

我在这上面花费了太多的时间。最初,我使用一个简单的“onAction”方法与 XML onclick 语句并行来控制位于 ExpandableListView 内部的按钮。我认为使用通货膨胀会很好,这样我就可以在运行时更好地控制按钮。 查看之前的帖子

您可以在此处 是我的最新尝试。我没有收到任何异常或错误,它只是什么也不做。我知道这个版本有点牵强,所以如果您有时间,请先查看上面的链接,了解我的其他一些尝试,然后再建议我可能已经尝试过的东西!

BrowseActivity.class

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse);

    ViewGroup parent = (ViewGroup) findViewById(R.id.expandLinLayout);

    ExpandableListView browseView = (ExpandableListView) findViewById(android.R.id.list);

    LayoutInflater inflater = LayoutInflater.from(this);

    View view = inflater.inflate(R.layout.row, parent);

    LinearLayout linLay = (LinearLayout) view
            .findViewById(R.id.LinearLayout1);
    TextView rowTxt = (TextView) view.findViewById(R.id.txtItem);

    rowTxt.setTextColor(Color.CYAN);

.........
}

包含列表的 browse.xml 代码:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:id="@+id/expandLinLayout"
>
<ExpandableListView 
android:id = "@android:id/list" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"
android:groupIndicator="@drawable/my_group_statelist"

>  
</ExpandableListView>

</LinearLayout>

最后是 row.xml 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:orientation="vertical" 


>
<TextView 
android:layout_gravity="center_vertical|right" 
android:id="@+id/txtItem" 
android:text="Item" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 


></TextView>

</LinearLayout>

任何帮助或建议将不胜感激。

I have spent entirely too much time on this. Originally, I was using a simple "onAction" method in parallel with an XML onclick statement to control a button located inside of my ExpandableListView. I thought it would be nice to use inflation so I could have more control of the button during runtime. You can see an earlier post HERE

This is my latest attempt. I do not get any exceptions or errors, it just does nothing. I know this version is a little far fetched so if you have the time check out the link above for some of my other attempts before suggesting something I may have already tried!

BrowseActivity.class

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browse);

    ViewGroup parent = (ViewGroup) findViewById(R.id.expandLinLayout);

    ExpandableListView browseView = (ExpandableListView) findViewById(android.R.id.list);

    LayoutInflater inflater = LayoutInflater.from(this);

    View view = inflater.inflate(R.layout.row, parent);

    LinearLayout linLay = (LinearLayout) view
            .findViewById(R.id.LinearLayout1);
    TextView rowTxt = (TextView) view.findViewById(R.id.txtItem);

    rowTxt.setTextColor(Color.CYAN);

.........
}

The browse.xml code that contains the list:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:id="@+id/expandLinLayout"
>
<ExpandableListView 
android:id = "@android:id/list" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"
android:groupIndicator="@drawable/my_group_statelist"

>  
</ExpandableListView>

</LinearLayout>

And finally the row.xml code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:orientation="vertical" 


>
<TextView 
android:layout_gravity="center_vertical|right" 
android:id="@+id/txtItem" 
android:text="Item" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 


></TextView>

</LinearLayout>

Any help or suggestions would be MUCH appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明明#如月 2024-11-25 14:18:24

尝试这个来初始化布局充气机

LayoutInflater inflater = (LayoutInflater)context.getSystemService
  (Context.LAYOUT_INFLATER_SERVICE);

Try this to initialize layout inflater

LayoutInflater inflater = (LayoutInflater)context.getSystemService
  (Context.LAYOUT_INFLATER_SERVICE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文