下面是我複製和編輯的一些代碼。如果我進行ColorsActivity擴展活動,一切正常。但是,如果它擴展ListActivity,它給了我錯誤,「你的內容必須有一個ListView誰是ID屬性是android.R.Id.List」。Android ListView錯誤
有人可以向我解釋這個嗎?
public class ColorsActivity extends Activity {
/** Called when the activity is first created. */
//ListView that will hold our items references back to main.xml
ListView lstTest;
//Array Adapter that will hold our ArrayList and display the items on the ListView
SeekBarAdaptor seekBarAdaptor;
//List that will host our items and allow us to modify that array adapter
ArrayList<SeekBar> seekBarArrayList=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seekbarlist);
//Initialize ListView
lstTest= (ListView)findViewById(R.id.myList);
//Initialize our ArrayList
seekBarArrayList = new ArrayList<SeekBar>();
//Initialize our array adapter notice how it references the listitems.xml layout
seekBarAdaptor = new SeekBarAdaptor(ColorsActivity.this, R.layout.seekbars,seekBarArrayList);
SeekBar red = new SeekBar(ColorsActivity.this);
SeekBar blue = new SeekBar(ColorsActivity.this);
//Set the above adapter as the adapter of choice for our list
lstTest.setAdapter(seekBarAdaptor);
seekBarArrayList.add(red);
seekBarArrayList.add(blue);
//Instantiate the Web Service Class with he URL of the web service not that you must pass
//WebService webService = new WebService("http://www.sumasoftware.com/alerts/GetAlerts.php");
//Pass the parameters if needed , if not then pass dummy one as follows
Map<String, String> params = new HashMap<String, String>();
params.put("var", "");
//Get JSON response from server the "" are where the method name would normally go if needed example
// webService.webGet("getMoreAllerts", params);
//String response = webService.webGet("", params);
/*try
{
//Parse Response into our object
Type collectionType = new TypeToken<ArrayList<alerts>>(){}.getType();
//JSON expects an list so can't use our ArrayList from the lstart
List<alerts> lst= new Gson().fromJson(response, collectionType);
//Now that we have that list lets add it to the ArrayList which will hold our items.
for(alerts l : lst)
{
alrts.add(l);
}
//Since we've modified the arrayList we now need to notify the adapter that
//its data has changed so that it updates the UI
arrayAdapter.notifyDataSetChanged();
}
catch(Exception e)
{
Log.d("Error: ", e.getMessage());
}*/
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ListView
android:id="@+id/myList"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
看起來好像是 android:id =「@ android:id/list」 works但是 android:id =「@ android:id/mylist」 沒有。 錯誤:找不到與給定名稱匹配的資源。在值爲@android的id:id/mylist – Spectrem 2012-03-07 04:57:39
您指的是「@android:id/mylist」,它正在尋找一個在Android資源中不存在的id。該ID中的@ android位表示'查看'mylist'的Android系統資源,這根本就不存在。 – 2012-03-07 05:02:55