OnItemClick, Intent, startActivity errors

My code is:

package elf.app;
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.ListView;
import elf.app.entity.ELFList;
import elf.app.entity.Entry;
import elf.app.test.FakeComm;

// TODO Kunna skicka att något är färdigt (ett rum är städat).

public class RoomListActivity extends ListActivity {
private ELFList eList;
//  private FakeComm fakecomm;
private Bundle extras;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.extras = getIntent().getExtras();
    eList = new ELFList();

//      fakecomm = new FakeComm();
//      eList.add(fakecomm.getData());

    String[] strArr = {"asd","sdf","dfg"};
    eList.add(strArr);

    String[] str = eList.returnNames();


    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, str));

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Entry e = eList.getEntry(position);
            String roominfo = e.toString();


            Intent intent = new Intent(this, RoomInfoActivity.class);
            intent.putExtra("entry",roominfo);
            this.startActivity(intent);

                // old stuff
            // String message;
            // message = eList.getEntryInfo(position);
            // Toast.makeText(getApplicationContext(),
            // message, Toast.LENGTH_SHORT).show();
        }
    });
}

}

I get errors in the following lines:

Intent intent = new Intent(this, RoomInfoActivity.class);

and

this.startActivity(intent);

I don’t have much information why I get these errors, the exact output in the editor for these errors:

  • "Intent constructor (new AdapterView.OnItemClickListener () {}, Class) is undefined"
  • "The startActivity (Intent) method is undefined for the type new AdapterView.OnItemClickListener () {}"

I am new to Android, so please keep this in mind, however I have studied Java for about a year.

+3
source share
2 answers

Fix

Intent intent = new Intent(this, RoomInfoActivity.class);

to

Intent intent = new Intent(RoomListActivity.this, RoomInfoActivity.class);

, this OnClickListener. , Activity this. - - . this, startActivity() -.

+9

Intent intent = new Intent(RoomListActivity.this, RoomInfoActivity.class);
intent.putExtra("entry",roominfo);
RoomListActivity.this.startActivity(intent);
+1

All Articles