2012-07-11 32 views
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」級。查詢有關arrayadapter

謝謝。

回答

0

R代表「資源」。 Android已經構建了android.R。*命名空間中的資源,並且您的應用程序在your_app_namespace.R。*命名空間中有資源。

爲什麼你應該使用資源有很多原因,但其中之一是支持多種語言和屏幕尺寸。

例如,對於一個活動,您可能有一個名爲「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命名空間的一部分,因爲它主要用於小部件。

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小部件。

同樣在一般情況下,Adapters是android ui工具包中一個數據源和UI組件之間的接口,適配器用於將數據提供給ui工具包。