android 中的 MVC 从资源填充列表视图



似乎它们应该是一种仅使用 xml 使用 android:resource 或 android:entries 来静态填充带有按钮数组的列表视图的方法。我更喜欢与我的主布局分开的资源 xml 文件。如果我理解 MVC,视图更像是一个静态的东西,因为控制器有视图的侦听器并对视图进行更改。我不知道字符串数组是否可以容纳按钮对象或我出错的地方。有什么建议吗?哦,按钮都应该具有相同的属性,但也许这是另一个问题?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/MainFrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
package="com.union.doogie"
android:animateLayoutChanges="true"
android:layoutMode="opticalBounds"
android:visibility="visible"
tools:context=".MainActivity" >
<ListView
    android:id="@+id/listViewmain"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:entries="@buttons/Buttons" >
   <TextView
       android:layout_width="match_parent"
       android:layout_height="match_parent" >
   </TextView>
 </ListView>
</FrameLayout>

Android 允许您通过 @+id/your_id 表示法在布局文件中动态定义用户界面组件的 ID。

若要控制 ID,还可以在/res/values 文件夹中创建一个名为 ids.xml 的文件,并定义此文件中的所有 ID。

 <?xml version="1.0" encoding="utf-8"?>
 <resources>
 <item name="button1" type="id"/>
 </resources> 

这允许您直接在布局文件中使用该 ID。

<ListView
android:id="@+id/listViewmain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@id/button1" >
<TextView
   android:layout_width="match_parent"
   android:layout_height="match_parent" >
</TextView>
</ListView>

最新更新