Мне нужно расширяет ListView для создания пользовательского компонента.
Я хотел бы поставить кнопку поиска внизу слева плавающим.
Когда я запускаю генерировать ошибку в onMessure.
Этот код является фрагментом, в оригинальном коде есть много других вещей.
Я пытаюсь изменить родительский элемент ViewGroup на ноль, но я получаю ту же ошибку.
mPainelView = inflater.inflate(R.layout.longlist_painel, null);
Пользовательский вид:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/longlist_painel_seek"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@android:drawable/ic_menu_search" /></FrameLayout>
Расширенный ListView:
public class List2 extends ListView {
private View mPainelView;
private int mPainelViewWidth;
private int mPainelViewHeight;
public List2(Context context) {
super(context);
createPainel();
}
public List2(Context context, AttributeSet attrs) {
super(context, attrs);
createPainel();
}
public List2(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
createPainel();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (mPainelView != null) {
measureChild(mPainelView, widthMeasureSpec, heightMeasureSpec);
mPainelViewWidth = mPainelView.getMeasuredWidth();
mPainelViewHeight = mPainelView.getMeasuredHeight();
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (mPainelView != null) {
mPainelView.layout(0, this.getBottom()-mPainelViewHeight, mPainelViewWidth, mPainelViewHeight);
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
drawChild(canvas, mPainelView, getDrawingTime());
}
private void createPainel(){
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mPainelView = inflater.inflate(R.layout.longlist_painel, this);
}
}
Ошибка:
java.lang.NullPointerException
at android.view.ViewGroup.measureChild(ViewGroup.java:3098)
at com.rodrigo.comp.LongList2.onMeasure(List2.java:40)
at android.view.View.measure(View.java:8173)