要素が を含むおよび にGridView
基づいているがあります。FrameLayout の xml ファイルは次のとおりです。FrameLayout
ImageView
CheckedTextView
<FrameLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:id="@+id/gridImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="false">
</ImageView>
<CheckedTextView
android:id="@+id/imageTick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal|bottom"
android:checkMark="@drawable/icon"
android:checked="false"
android:visibility="invisible"
>
</CheckedTextView>
</FrameLayout>
編集:これは、getView()
各要素に使用するアダプターのメソッドです:
public View getView(int position, View convertView, ViewGroup parent) {
Log.d("getView()", position+"");
View v;
ImageView imageView;
if(convertView == null) {
v = LayoutInflater.from(mContext).inflate(R.layout.photo_text_view, null);
v.setLayoutParams(new GridView.LayoutParams(100,100));
}
else
{
v = convertView;
}
imageView = (ImageView) v.findViewById(R.id.image);
imageView.setImageBitmap(mThumbsIds.get().get(position));
v.setPadding(8, 8, 8, 8);
return v;
}
私のアクティビティ クラスでは、コンテキスト メニューをロードし、オプションを選択したら、その要素を次のようにCheckedTextView
表示します。GridView
GridView gridView = (GridView) findViewById(R.id.gridview);
View selected =gridView.getChildAt(position);
CheckedTextView selectedCheck = (CheckedTextView)selected.findViewById(R.id.imageTick);
selectedCheck.setChecked(true);
selectedCheck.setVisibility(View.VISIBLE);
したがって、この時点から次の 2 つのことが潜在的に発生する可能性があります。
1)位置0の要素を選択すると、CheckedTextViewが表示されますが、GridViewを下にスクロールすると、別の要素(位置17など)にもCheckedTextViewが表示されます。これは、下に向かって下にスクロールすると、ランダムな要素で続きます。
2) 下に向かって要素を選択し、上にスクロールして戻り、いずれかのメソッドを実行してすべての CheckedTextView を非表示にするNullPointerException
と、下の要素に対して a がスローされます。これはView selected =gridView.getChildAt(position);
、selected が null になる時点で発生します。
何が起きてる?これらのランダムな CheckedTextView が表示されるのはなぜですか? また、例外が発生するのはなぜですか?