【发布时间】:2016-11-11 06:25:43
【问题描述】:
我正在开发 Android 应用程序,它需要 listview 和 ArrayAdapter。现在我想要 onItemClickListener 在这个列表视图上。但是 IDE Anacode(与 Eclipse 相同)显示错误!
我已经尝试了此类问题帖子中的所有答案。但没有帮助!
请帮忙
//the code
package edward.harsh.friends;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
public class ListViewSampleActivity extends Activity
{
ListView mCountriesLV;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/**
* Get the control instances from the main.xml layout
*/
mCountriesLV = (ListView) findViewById(R.id.countriesLV);
mCountriesLV.setAdapter(new CountriesAdapter(this, R.layout.listview_country_row, mCountriesList));
mCountriesLV.setOnItemClickListener(
new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext()," name", Toast.LENGTH_SHORT).show();
}
});
}
}
错误信息是
The method setOnItemClickListener(AdapterView.OnItemClickListener in the type
AdapterView <ListAdapter> is not applicable for the arguments (new OnItemClickListener(){})
OnItemClickListener cannot be resolved to a type
正如某些人所建议的那样。我什至试过这个
mCountriesLV.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext()," name", Toast.LENGTH_SHORT).show();
}
});
但它会引发另一个错误
The type new AdapterView.OnItemClickListener(){} must implement the inherited abstract method
AdapterView.OnItemClickListener.onItemClick(AdapterView <?>, View, int, long)
【问题讨论】:
-
请在您的问题中添加错误的位置和错误...
-
为什么会有 iframe 标签?
-
可能你的 CountryAdapter.class 中有一些 onClickListeners。删除它们
-
@Dan 我编辑了问题
-
我已经导入了android.widget.*;和 android.view*; @HsRaja
标签: java android listview android-arrayadapter onitemclicklistener