0

だから私は今かなり混乱しています。XML レイアウトを使用しているので、次のように空のビューを表示できます。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/samples_empty"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </RelativeLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" >

    </ListView>

</RelativeLayout>

おそらく、ここで何十億回も見たことがあるでしょう。

したがって、 setContentView(R.layout.foo) を実行すると、初めて機能しますが、このアクティビティに戻ると (onPause が呼び出されてから onResume が呼び出されたように)、次のようになります。

代替テキスト

私はアダプターを呼び出しnotifyDataSetChanged();、それは正常に動作しますが、得られないのはなぜ2回描画されるのですか?

新しい ListView を作成してビューに追加しているわけではありません。

getViewアダプターの方法:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    RecordView av;
    if(convertView == null){
        av = new RecordView(mCtx, this, mRecords[position], position);
    }else{
        av = (RecordView) convertView;
        av.setRecord(mRecords[position]);
    }
    return av;
}

普段ならこんな感じだろうな…

代替テキスト

ノート

これは毎回発生するわけではなく、単一のイベントが発生したときに発生するわけではありませんが、発生した場合は、別の画面から戻ったときに発生します。

アップデート

上に別のアクティビティがあることに気付きました (Facebook のチャット ヘッドのような透過的なもので、そのときに問題が発生したことがわかりました。onResume では発生していないようですが、onPause で発生する可能性が高く、実際にはでは何もしないでください。

4

2 に答える 2