我正在尝试将方法setOnItemClickListener设置为listview,但它报告错误
码
//*******///
public class ViewAdapter extends BaseAdapter
{
LayoutInflater mInflater;
public ViewAdapter ()
{
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount ()
{
return favoriteList.size();
}
@Override
public Object getItem (int position)
{
return null;
}
@Override
public long getItemId (int position)
{
return position;
}
@Override
public View getView (final int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.itemlista, null);
}
final TextView infraText = (TextView) convertView.findViewById(R.id.tv_infra);
infraText.setText(favoriteList.get(position).getInfraccion());
final TextView ageText = (TextView) convertView.findViewById(R.id.matricula);
ageText.setText(favoriteList.get(position).getMatricula());
final TextView fechaText = (TextView) convertView.findViewById(R.id.tv_dia);
fechaText.setText(favoriteList.get(position).getFecha());
final TextView horaText = (TextView) convertView.findViewById(R.id.tv_hora);
horaText.setText(favoriteList.get(position).getHora());
final TextView tipoinfraText = (TextView) convertView.findViewById(R.id.tv_tipo);
tipoinfraText.setText(favoriteList.get(position).getTipoinfra());
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0,
View arg1, int position, long arg3)
{
Toast.makeText(InciEnviadasActivity.this, "posicion:" + position, Toast.LENGTH_LONG).show();
}
});
return convertView;
}
}
创建//
//******//
//list = (Button) findViewById(R.id.list);
list =(ImageView) findViewById(R.id.list);
list.setOnClickListener(listOnClick);
listView = (ListView) findViewById(R.id.listView);
db = new BBDD(this, "BBDD", null, 1);
;
View.OnClickListener listOnClick = new OnClickListener()
{
@Override
public void onClick (View v)
{
favoriteList = db.getFavList();
listView.setAdapter(new ViewAdapter());
}
};
//list = (Button) findViewById(R.id.list);
list.setOnClickListener(listOnClick);
listView = (ListView) findViewById(R.id.listView);
db = new BBDD(this, "BBDD", null, 1);
;
//******/
我能做错什么?有什么建议可以解决吗?
我顺便从内部SQlite数据库填充ListView。
更新:已解决,我对名称LISTVIEW感到困惑,我正在尝试将方法分配给IMAGEVIEW,我很抱歉
答案 0 :(得分:4)
您尝试将setOnItemClickListener
改为ImageView
。
应为listView.setOnItemClickListener...
答案 1 :(得分:2)
list
是ImageView
,setOnItemClickListener
没有ImageView
。
在适配器的getView
中设置新适配器也不正确,只在Activity
中设置一次。与在onClick
方法中设置新适配器相同,这不是一个好主意。