0

您好我正在尝试制作一个应用程序,该应用程序使用 listView 显示项目列表,并且当用户从列表中选择一个项目时。该应用程序将调用链接到所选项目的特定类,但是我在第二个@override 遇到错误,说覆盖必须覆盖超类。这是我的类和 xml 代码。

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

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/botanicgate" />

<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

</LinearLayout>

 package com.fyp.gulliver;

 import android.app.ListActivity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;

 public class HotSpot extends ListActivity{
/** Called when the activity is first created. */
String places[] =  {"BotanicGarden", "Sentosa"};
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hotspot);
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(new ArrayAdapter
            (HotSpot.this, android.R.layout.simple_list_item_1, 
                    places));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // TODO Auto-generated method stub
            Class ourClass;
            String item = ((TextView)view).getText().toString();
            try {
                ourClass = Class.forName
                        ("com.fyp.gulliver." + item);
                Intent ourIntent = new Intent(HotSpot.this, ourClass);
                startActivity(ourIntent);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }); 
     }
    }

由于我还是 android 的新手,因此我不知道我犯了什么错误,如果其他人可以帮助我解决我的错误,我将不胜感激谢谢:D

4

1 回答 1

0

尝试改变这个:

listView.setOnItemClickListener(new OnItemClickListener();

listView.setOnItemClickListener(new AdapterView.OnItemClickListener();

并删除第二个@Override

于 2012-09-24T07:06:47.043 回答