「Android/レイアウト/addViewされているか判定」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==自分自身のviewが他にaddviewされているか判定する方法== <pre> public class HogeView extends FrameLayout { public HogeView(Context context) {...」) |
(相違点なし)
|
2018年11月19日 (月) 18:26時点における版
自分自身のviewが他にaddviewされているか判定する方法
public class HogeView extends FrameLayout {
public HogeView(Context context) {
super(context,null);
}
public HogeView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public HogeView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
MainActivity.java;
HogeView view = new HogeView(); this.addView(view);
HogeView.java
View v = HogeView.this;
View parentv = (View) v.getParent();
View parent2v = (View) parentv.getParent();
if (parentv != null) {
log.debug_i(TAG, "1つ前の親viewはaddされている");
} else {
log.debug_i(TAG, "1つ前の親viewはaddされていない");
}
if (parent2v != null) {
log.debug_i(TAG, "2つ前の親viewはaddされている");
} else {
log.debug_i(TAG, "2つ前の親viewはaddされていない");
}
