2011-04-15 46 views
0

我正在使用xml文件,通過它我通過變量passkey.later訪問字符串,我將其分配給strPassword。我收到錯誤setListAdapter.Here是我的代碼..android的活動

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<string-array name="passkey"> 
    <item>1234</item> 
    </string-array> 
</resources> 

public class AdminLogin extends Activity 
{ 
    public void onCreate(Bundle bdlActivity) 
    { 
     String[] strPassword = getResources().getStringArray(R.array.passkey); 

     setListAdapter(new ArrayAdapter<String>(this,R.layout.adminlogin, 
       R.id.Editpassword, strPassword)) 
     //button events 
    } 
+1

你會得到什麼錯誤?請編輯您的問題並添加logcat輸出。 – 2011-04-15 09:43:03

+1

您應該避免以純文本格式存儲任何密碼。 – 2011-04-15 09:44:10

+0

我的錯誤是:方法setAdapter(ArrayAdapter )是未定義的類型AdminLogin – sujay 2011-04-15 09:54:12

回答

0

您需要與ListActivty擴展您的類。你不能在簡單的活動中實例化ListView。

0

您可以從一個簡單的活動也做到這一點:

說你有一個主要的佈局,如: mylayout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <Button android:id="@+id/btn_ok" android:layout_height="wrap_content" 
     android:layout_width="wrap_content" android:text="OK" android:layout_alignParentBottom="true" /> 
    <ListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:layout_above="@id/btn_ok" /> 
</RelativeLayout> 

這將是您的活動的佈局,它的列表視圖(@id/listview

您的ActivityonCreate方法應該看起來像這樣:

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.mylayout); 

    final ListView listView = (ListView) findViewById(R.id.listview); 
    listView.setListAdapter(new ArrayAdapter<String>(this, R.layout.adminlogin, 
       R.id.Editpassword, strPassword)) 
}