2017-11-20 10 views
0

文字列リソースファイルで宣言された単純な文字列配列をリストビューに表示したい。私のデバイスでアプリをテストすると、すべてうまく動作します。しかし、アンドロイドスタジオのデザインビューでは、私は文字列リソースファイルの値ではないと思ういくつかのデフォルト値を取得します。デザインビューにリストビューの文字列配列の値が反映されない

これが不具合か、バグか、ここで何か間違っているのですか?

のstrings.xml

<resources> 
    <string name="app_name">Starbuzz</string> 
    <string name="starbuzz_logo">Starbuzz logo</string> 
    <string-array name="options"> 
     <item>Drinks</item> 
     <item>Food</item> 
     <item>Stores</item> 
    </string-array> 
</resources> 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.hfad.starbuzz.MainActivity"> 
<ImageView 
    android:layout_width="200dp" 
    android:layout_height="100dp" 
    android:src="@drawable/starbuzz_logo" 
    android:contentDescription="@string/starbuzz_logo"/> 
    <ListView 
     android:id="@+id/list_options" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:entries="@array/options"> 
    </ListView> 
</LinearLayout> 

enter image description here

+0

アンドロイドデザインルールの場合、そのリストビューはレンダリングされません。誰も私にそれがなぜそうであるかを教えてもらえますか? –

答えて

0

Androidデザインルールでは、プレビューで表示され、xmlのビューはデータではなくレンダリングされます。したがって、ここでデータを表示する場合は、デバイスまたはエミュレータで実行する必要があります。

+0

これはリストデータのみですか?他のテキストや画像がレンダリングされているのが見えますか? –

+0

はい、それはリストのみです。他のテキストや画像は簡単にレンダリングされます。あなたはアダプタを持っている必要がありますリスト –

+0

それは私のためにそれをクリアする必要があります。私の次のタスクでアダプターを学ぶ:)。ありがとう@ankit patidar! –

0

私はあなたが共有画面が完全に罰金ですのAndroid StudioでのXMLファイルのプレビューであると考えています。 listviewのプレビューは常にデフォルトのテンプレートとして表示されます。リストビューのデータエントリは、エミュレータまたは実際のデバイスのいずれかでアプリケーションを実行する場合にのみ設定されます。

関連する問題