0
今天,我突然遇到了以前從未見過的問題。幫我:)在Android的適配器面臨的問題,有什麼錯?
public class ShowAnimalsListActivity extends Activity
{
ArrayList<String> animalsNameList;
public void onCreate(Bundle saveInstanceState)
{
super.onCreate(saveInstanceState);
setContentView(R.layout.animal_list);
// Get the reference of ListViewAnimals
ListView animalList=(ListView)findViewById(R.id.listViewAnimals);
animalsNameList = new ArrayList<String>();
getAnimalNames();
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(this,android.R.layout.simple_list_item1, animalsNameList);
// Set The Adapter
animalList.setAdapter(
animalList.setOnItemClickListener(new OnItemClickListener()
{
// argument position gives the index of item which is clicked
public void onItemClick(AdapterView<?> arg0, View v,int position, long arg3)
{
String selectedAnimal=animalsNameList.get(position);
Toast.makeText(getApplicationContext(), "Animal Selected : "+selectedAnimal, Toast.LENGTH_LONG).show();
}
});
}
這是什麼問題?你沒有提到什麼是錯的。 – Zorfling
發佈你得到的錯誤 – Jerry
在你做任何其他事情之前,解決這個問題......你的'animalList.setAdapter('不完整,將其改爲'animalList.setAdapter(arrayAdapter);' – Swap