2011-12-04 8 views
1

誰でも私が間違っていることを教えてもらえますか? Eclipseは私にエラーや警告を与えていませんが、私がエミュレータを実行すると、ListViewに値が設定されていません。どんな助けも大歓迎です。ありがとう。配列Array.xmlから、カスタムArrayAdapterクラスを使用してListViewに配列を取得しようとしています。どうしましたか?

これはのonCreate内にある:

ListView bedList = (ListView) findViewById(R.id.refineBeds); 
bedList.setVisibility(View.VISIBLE); 
bedList.setAdapter(new MArrayAdapter(this, R.array.beds)); 
bedList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

これは私が私のアダプタとして使用しようとしているカスタム内部クラスです:

private static class MArrayAdapter extends ArrayAdapter<String> { 
    public MArrayAdapter(final Context context, final int objects) { 
    super(context, R.layout.item_single, objects); 
} 

@Override 
public View getView(final int position, final View convertView, final ViewGroup parent) { 
    final CheckedTextView view = (CheckedTextView) 
    super.getView(position, convertView, parent); 
    view.setChecked(position == 2); return view; 
    } 
} 
+0

ロードしようとしている配列のxmlを投稿してください。 –

+0

XMLにエラーはありませんか? – sparksalot

答えて

4

は、このようなcusomレイアウトすることなく、第1試してみてください次のコンストラクタをR.array.bedsから文字列要素のリストを作成してみてくださいし、使用し、以下の定義に応答し、そして最終的にあなたが調整することができます

... 

String[] bedsArray = getResources().getStringArray(R.array.beds); 

bedList.setListAdapter(new ArrayAdapter<String>(
          this, 
          android.R.layout.simple_expandable_list_item_1, 
          bedsArray)); 

... 
+0

あなたが言及したように、getResources.getStringArrayを使用して文字列配列を作成するだけでした。次に、String []をコンストラクタに追加するだけで、すべてがうまくいきます!ありがとうございました! –

0

問題は

以下、このラインであります
new MArrayAdapter(this, R.array.beds) 

このcor

public ArrayAdapter (Context context, int textViewResourceId) 

public ArrayAdapter (Context context, int textViewResourceId, List<T> objects) 
関連する問題