2013-01-12 31 views
0

我已經擴展微調類爲了定製它,但我無法弄清楚如何在我的代碼中使用它。Android - 如何使用自定義微調器

public class mySpinner extends Spinner { 
...... 
} 

我有一個使用微調現有的活動,我想改變它使用mySpinner類。

原:

Spinner spinner = (Spinner) textEntryView 
      .findViewById(R.id.account_spinner); 

<Spinner 
    android:id="@+id/account_spinner" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:prompt="@string/ADALabel1" 
    android:layout_alignLeft="@+id/newassetsymbol" 
    android:layout_below="@+id/assetclass_spinner" /> 

開始我嘗試:

mySpinner spinner = (Spinner) textEntryView 
      .findViewById(R.id.account_spinner); 

編譯錯誤(有意義)。 然後我試過:

mySpinner spinner = (mySpinner) textEntryView 
      .findViewById(R.id.account_spinner); 

運行時拋出錯誤。

<mySpinner 
    android:id="@+id/account_spinner" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:prompt="@string/ADALabel1" 
    android:layout_alignLeft="@+id/newassetsymbol" 
    android:layout_below="@+id/assetclass_spinner" /> 

6月1日至12日:50:02.664:E/AndroidRuntime(597):拋出java.lang.ClassNotFoundException:致android.view.mySpinner在裝載機 然後我與前行改變了佈局dalvik.system.PathClassLoader [/data/app/org.sample.sample-1.apk]

這似乎並不困難,但我失去了一些東西。有人可以幫忙嗎? 謝謝。

回答

1

在XML中使用自定義View組件時,需要使用完整的類路徑。

<com.example.appname.mySpinner /> 
+0

工作正常。謝謝。 – Clavijo