簡體   English   中英

'onListItemClick'方法使Eclipse不斷出錯

[英]'onListItemClick' method keeps Eclipse giving me errors

我正在閱讀針對傻瓜的Android應用程序開發,並且在第9章中編寫了任務提醒應用程序。 我有一個onListItemClick方法,但是Eclipse不斷給出錯誤信息。

package com.dummies.android.taskreminder;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.*;

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




            String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin" };


            ArrayAdapter<String> adapter =
                new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
            setListAdapter(adapter); 

            @Override
            protected void onListItemClick(ListView l, View v, int position, long id) {
                super.onListItemClick(l, v, position, id);
            }


        }
    }

我的錯誤: 我的錯誤

Eclipse表示:“視圖無法解析為類型”“令牌上的語法錯誤...預期”(5x)“ void是變量onListItemClick的無效類型”

我做錯了什么?

嘗試這個

package com.dummies.android.taskreminder;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.*;

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

            String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin" };

            ArrayAdapter<String> adapter =
                new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
            setListAdapter(adapter); 
        }

        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {
            super.onListItemClick(l, v, position, id);
        }

    }

您已將onListItemClick方法放置在onCreate方法中。 將其移出該方法。

您可能還缺少導入語句。

您試圖覆蓋onCreate方法中的onListItemClick方法。 您需要將該代碼帶到onCreate()方法之外。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM