2014-12-27 76 views
0

我已經爲同一個ListView創建了一個簡單的ListActivity和一個名爲people_list_row.xml的自定義列表項。 我正在使用自定義陣列adqapter peopleCustomArrayAdapter.java。在這個自定義數組適配器Eclipse內部拋出錯誤「people_list_row無法解析或不是字段」。雖然佈局people_list_row目前R.java投擲錯誤佈局未定義。即使存在於R.java

沒有錯誤。我試圖清理,建立這個項目仍然沒有運氣。

error in eclipse

//Inside Custom Array Adapter 
    public class peopleCustomArrayAdapter extends ArrayAdapter<String> implements OnClickListener{ 
     String[] values; 
     public peopleCustomArrayAdapter(Context context,String[] values) { 
      super(context,R.layout.people_list_row1,values); 
      this.values=values; 
     } 
    } 

<!-- people_list_row.xml --> 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/RelativeLayout1" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <LinearLayout android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" android:background="#035633" 
     android:orientation="vertical"> 
     <TextView android:id="@+id/textName" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="TextView" /> 
    </LinearLayout> 
</RelativeLayout> 

回答

1

由於適配器(ArrayAdapter)類不會隱導入資源,你必須手動導入:

import com.example.package.R; 

你不會需要做的是,在如一個延續Activity的類。

+0

是的,你是對的。而不是'import android.R',我不得不使用'import com.example.package_name.R;'。雖然我發現自己的解決方案無法更新答案。無論如何感謝您的寶貴時間。 :) – AnonymousCoder 2014-12-31 15:56:18