开发者

'onListItemClick' method keeps Eclipse giving me errors

开发者 https://www.devze.com 2023-03-23 05:18 出处:网络
I\'m reading Android Application Developement for Dummies and i\'m at Chapter 9 where I\'m writing a Task reminder app. I have a onListItemClick method, but Eclipse keeps giving errors....

I'm reading Android Application Developement for Dummies and i'm at Chapter 9 where I'm writing a Task reminder app. I have a onListItemClick method, but Eclipse keeps giving errors....

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, it开发者_如何学Cems);
            setListAdapter(adapter); 

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


        }
    }

my error: my error

Eclipse says: "View cannot be resolved to a type" "Syntax erroe on token ..... expected" (5x) "void is an invalid type for the variable onListItemClick"

What did I do wrong?


try this

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);
        }

    }


You have placed the onListItemClick method inside the onCreate method. Move it outside of that method.

You are probably also missing import statements.


You are trying to override the onListItemClick method inside the onCreate method. You need to take that code outside the onCreate() method.

0

精彩评论

暂无评论...
验证码 换一张
取 消