5

だから私はグーグルで検索し、おそらくばかげた見落としだと思うものへの答えを求めてSOを探しましたが、ここに行きます。

アプリケーションの他の場所で使用しているオブジェクトのリストから作成しているものを入力していますListView。電話をかける前と後の両方で、アダプターにアイテムがあることArrayAdapterを確認しました。ただし、私のアプリケーションには何も表示されません。getCount.setAdapter()

私のメインレイアウトres/layout/playlistview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/playlist_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#80000000"
android:gravity="center"
android:orientation="horizontal" >

<ListView
    android:id="@+id/playlistview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="#206"
    android:background="#602" >

</ListView>

</LinearLayout>

(色を設定して、何が起こっているのかをより簡単に確認できるようにしました)

textview各アイテムのres/layout/singlelistitem

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/single_item"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:padding="5dp" 
    android:background="#206">
</TextView>

そして私がそれを移入するために使用するコード:

private ListView playlistView;

private void buildPlaylistView() {
playlistView = (ListView)findViewById(R.id.playlistview);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.singlelistitem, R.id.single_item, playlist.titlesAsArray());

playlistView.setAdapter(adapter);

playlistView.setVisibility(View.VISIBLE);

adapter.notifyDataSetChanged();
((ArrayAdapter<String>)playlistView.getAdapter()).notifyDataSetChanged();
}

playlist.titlesAsArray()戻りString[]、動作します。

.notifyDataSetChanged()SOでそれを見つけて試してみたので、両方があります。

XMLandroid:layout_height内のオブジェクトのをに変更すると、それをラップするにある不透明な背景のみが表示されます。に設定すると、画面全体が(マゼンティッシュ)になります。ListViewwrap_contentLinearLayoutListView android:layout_heightmatch_parent#206

アイテムがあると表示さgetCount()れる前にアダプターをチェックすると。setAdapter()後で確認すると、ビュー自体から、同じ数のアイテムがあると表示されます。私はこれに完全に迷っていますが、何も表示されません。

4

1 に答える 1

4

android:orientation="horizontal"からに変更してみてくださいandroid:orientation="vertical"。修正される可能性があります。

于 2013-02-05T00:40:31.703 に答える