Android的OnItemClickListener不工作

Android的OnItemClickListener不工作

本文介绍了Android的OnItemClickListener不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是安卓2.3.3。我建立了一个布局一样,

I'm using android 2.3.3. I set up a layout like,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView android:id="@+id/mainList" android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

和我有操纵它

package org.dewsworld.ui;

import org.dewsworld.core.NBConfig;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class NewsBotActivity extends ListActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        setListAdapter( new ArrayAdapter<String>(this,
                                            android.R.layout.simple_list_item_1,
                                            NBConfig.topics));

        ListView listView = (ListView) findViewById(R.id.mainList) ;
        listView.setOnItemClickListener( new OnItemClickListener() {

        });
    }
}

使用eclise IDE中,当我setthe OnItemClickListener它给我的错误

Using eclise IDE, when I setthe OnItemClickListener it gives me the error

The method setOnItemClickListener(AdapterView.OnItemClickListener) in the type AdapterView<ListAdapter> is not applicable for the arguments (new
     OnItemClickListener(){})

我不解决这个问题。 [我已经添加的图像,并显示错误]

I can't fix this. [I've added an image with the error]

推荐答案

看来你已经导入了错误的OnItemClickListener,试试这个来代替,并删除android.view.View.OnClickListener进口

It seems you have imported the wrong OnItemClickListener, try this one instead, and remove import of android.view.View.OnClickListener

import android.widget.AdapterView.OnItemClickListener;

这篇关于Android的OnItemClickListener不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:32