gpt4 book ai didi

java - ListView 与 ArrayAdapter 中的 setOnItemClickListener 错误

转载 作者:行者123 更新时间:2023-12-01 09:16:00 24 4
gpt4 key购买 nike

我正在开发Android应用程序,它需要listviewArrayAdapter。现在我想在此 ListView 上 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)

最佳答案

尝试在setOnItemClickListener方法中添加AdapterView.OnItemClickListener(),它不适用于OnItemClickListener

mCountriesLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

}
});

关于java - ListView 与 ArrayAdapter 中的 setOnItemClickListener 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40542291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com