「Android/レイアウト/レイアウトファイルをjavaで取得」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「res/layout/video_item.xml <pre> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height...」) |
|||
| 行19: | 行19: | ||
LayoutInflater inflater = LayoutInflater.from(this); | LayoutInflater inflater = LayoutInflater.from(this); | ||
LinearLayout itemLayout = (LinearLayout)inflater.inflate(R.layout.video_item, null); | LinearLayout itemLayout = (LinearLayout)inflater.inflate(R.layout.video_item, null); | ||
| + | // id取得 | ||
| + | Button button = (Button)itemLayout.findViewById(R.id.button1); | ||
</pre> | </pre> | ||
2019年3月26日 (火) 16:34時点における版
res/layout/video_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/iconImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
hogehoge.java
import android.view.LayoutInflater; LayoutInflater inflater = LayoutInflater.from(this); LinearLayout itemLayout = (LinearLayout)inflater.inflate(R.layout.video_item, null); // id取得 Button button = (Button)itemLayout.findViewById(R.id.button1);
参考:http://inujirushi123.blog.fc2.com/blog-entry-27.html
参考:https://developer.android.com/reference/android/view/LayoutInflater
