這是Android應用程序項目的一部分,我有這段代碼我不能夠明白,setOnItemClickListener需要(AdapterView.OnItemClickListener監聽器)作爲參數,但其他方法void onItemClick也是在參數空間。我無法理解AdapterView.OnItemClickListener()的對象如何調用/使用onItemClick?基本代碼閱讀在android
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
String forecast = mForecastAdapter.getItem(position);
Intent intent = new Intent(getActivity(), MainActivity2Activity.class)
.putExtra(Intent.EXTRA_TEXT, forecast);
startActivity(intent);
}
})
listView通過OnItemClickListener接口調用onItemClick。 https://docs.oracle.com/javase/tutorial/java/concepts/interface.html – Toumash
請參閱此鏈接http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html –