在android中,如何从数据库中动态地为按钮分配名称?
这是我的主xml文件…我需要动态地为4个按钮分配名称…我怎么做?? 需要动态命名的四个按钮是 左上方 右上方 洛维夫特 右下角在android中,如何从数据库中动态地为按钮分配名称?,android,database,Android,Database,这是我的主xml文件…我需要动态地为4个按钮分配名称…我怎么做?? 需要动态命名的四个按钮是 左上方 右上方 洛维夫特 右下角 </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp"> <Button an
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<Button
android:id="@+id/UpperLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"/>
<Button
android:id="@+id/UpperRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/LowerLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
/>
<Button
android:id="@+id/LowerRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:textAlignment="center"
android:text="@string/answer"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<Button
android:id="@+id/UpperLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"/>
<Button
android:id="@+id/UpperRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/LowerLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
/>
<Button
android:id="@+id/LowerRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:textAlignment="center"
android:text="@string/answer"
/>
</LinearLayout>
这是我的主xml文件…我需要从数据库中为4个按钮动态分配名称…我如何才能做到???您只需在初始化
按钮
视图后使用它即可
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<Button
android:id="@+id/UpperLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"/>
<Button
android:id="@+id/UpperRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/LowerLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
/>
<Button
android:id="@+id/LowerRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:textAlignment="center"
android:text="@string/answer"
/>
</LinearLayout>
yourbutton1.setText("Button1");
yourbutton2.setText("Button2");
yourbutton3.setText("Button3");
yourbutton4.setText("Button4");
您可以通过Java来实现
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<Button
android:id="@+id/UpperLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"/>
<Button
android:id="@+id/UpperRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/LowerLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
/>
<Button
android:id="@+id/LowerRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center"
>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:textAlignment="center"
android:text="@string/answer"
/>
</LinearLayout>
button.setText("button name");
只需从数据库中获取名称并将其设置为按钮即可。是关于Android SQLite数据库的教程。