在gridview上调用invalidate会将EditText的颜色更改为白色

时间:2013-04-21 22:29:24

标签: android android-layout

我正在我的活动中绘制网格视图,如下所示:

AlbumGridAdapter albumAdapter = new AlbumGridAdapter(this);
GridView gv = (GridView) findViewById(R.id.grid);
gv.setAdapter(albumAdapter);

然后当我需要刷新视图时(在对话框中输入一些用户之后):

gv.setAdapter(new AlbumGridAdapter(getApplicationContext()));
gv.invalidate();

调用此函数后,我的EditTexts(下方)变为白色。除此之外,“刷新”正在发挥作用。

这是网格的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity$DummySectionFragment" >

<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="false"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:textSize="18sp"
android:gravity="center" 
android:layout_gravity="center"
android:textIsSelectable="false" />

<GridView
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp"
android:gravity="center" >
</GridView>

</RelativeLayout>

每个网格单元的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/grid_cell"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="3dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="3dp"
    android:paddingLeft="3dp"
    android:paddingRight="3dp"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:padding="1dp"
        android:src="@drawable/no_image"
        android:contentDescription="@string/image" />

    <TextView
        android:id="@+id/caption"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="2dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textIsSelectable="false" />

</LinearLayout>

1 个答案:

答案 0 :(得分:1)

尝试使用您的Activity而不是您的应用程序作为您提供给适配器的上下文。我猜这是因为你使用android:textAppearance="?android:attr/textAppearanceMedium",它指的是一个主题属性,你得到你的应用程序的主题,这可能与你的活动主题不同。