0
ArrayAdapter<String> arrayadapter=new 

ArrayAdapter<string>(Sipnner_apActivity.this,android.R.layout.simple_spinner_item,arrarylist);

ここで、クラスの意味とandroid.R.layout.simple_spinner_item、クラスがArrayadapterクラスに属しているwidget理由と「util」クラスに属していない理由を説明します。

ありがとうございました。

4

2 に答える 2

0

R は「リソース」の略です。Android は android.R.* 名前空間にリソースを組み込み、アプリケーションは your_app_namespace.R.* 名前空間にリソースを持っています。

リソースを使用する理由はたくさんありますが、その 1 つは、複数の言語と画面サイズをサポートするためです。

たとえば、アクティビティの場合、「helloworld.xml」というレイアウトがあるとします。Eclipse は your_app_namespace.R.layout.helloworld の定数値を生成します。

この helloworld.xml レイアウト ファイルは res/layout フォルダーにあります。ただし、アプリケーションがタブレットにインストールされている場合に helloworld.xml の外観を変えたい場合は、helloworld.xml の別のコピーを layout-large というフォルダーに入れることができます。使用する helloworld.xml が自動的に選択されます。

あなたの質問に答えるために、android.R.layout.simple_spinner_itemは Android がデフォルトで持っているレイアウトです。これを使用すると、単純なものが必要な場合に、スピナー アイテム用に独自のレイアウトを作成する必要がなくなります。

ArrayAdapter は主にウィジェットに使用されるため、util 名前空間の一部ではありません。

于 2012-07-11T17:44:38.903 に答える
0

これは android.R.layout.simple_spinner_item がどのように見えるかです:

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />

これは基本的に、arraylist 要素がバインドされる TextView ウィジェットとまったく同じテンプレートです。

また、一般に、アダプターは、データのソースと UI コンポーネントの間の android ui ツールキットのインターフェイスであり、アダプターはデータを ui ツールキットに供給するために使用されます。

于 2012-07-11T17:45:16.687 に答える