Android 如何为以编程方式添加的子菜单项使用布局文件

Android 如何为以编程方式添加的子菜单项使用布局文件,android,navigation-drawer,Android,Navigation Drawer,我正在以编程方式构建抽屉导航的一部分。我遇到的问题是,我需要能够动态地设置标题(我目前可以这样做),以及在标题后显示一个整数,因此类似于有趣的东西122 这就是我将文件夹添加到菜单的方式(这是在一个循环中,我永远不知道有多少文件夹或它们的名称,它会改变) 因此,我可以添加标题正确的项目,但问题是我还需要一个整数,整数字段确实需要是一个文本视图,这样我可以在用户与项目交互时增加或减少数字,但我无法确定如何将其设置为使用视图/布局资源文件 最终,我希望能够设置这样的东西,我可以放入每个项目中,然后访

我正在以编程方式构建抽屉导航的一部分。我遇到的问题是,我需要能够动态地设置标题(我目前可以这样做),以及在标题后显示一个整数,因此类似于
有趣的东西122

这就是我将文件夹添加到菜单的方式(这是在一个循环中,我永远不知道有多少文件夹或它们的名称,它会改变)

因此,我可以添加标题正确的项目,但问题是我还需要一个整数,整数字段确实需要是一个文本视图,这样我可以在用户与项目交互时增加或减少数字,但我无法确定如何将其设置为使用视图/布局资源文件

最终,我希望能够设置这样的东西,我可以放入每个项目中,然后访问计数并更改它

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/folder_menu_item_container">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/folder_menu_item_title"
    android:text="{title} "/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/folder_menu_item_unread_count"
    android:text="{unread_count}" />

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/folder_menu_item_container">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/folder_menu_item_title"
    android:text="{title} "/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/folder_menu_item_unread_count"
    android:text="{unread_count}" />

</LinearLayout>