onItemClick,意图,startActivity错误 [英] onItemClick, Intent, startActivity errors
问题描述
我的code:
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'm getting errors at the following lines:
Intent intent = new Intent(this, RoomInfoActivity.class);
和
this.startActivity(intent);
我没有太多的线索,为什么我得到这些错误,在编辑这些错误的确切输出是:
I don't have much of a clue why I get these errors, the exact output in the editor for these errors are:
- 在构造意图(新AdapterView.OnItemClickListener(){},类)是不确定的
- 的方法startActivity(意向)是未定义的类型新AdapterView.OnItemClickListener(){}
我是一个Android新手,所以请考虑到这一点,但是我研究Java的大约一年。
I'm an Android newbie so please take that into consideration, however I have studied Java for about a year.
推荐答案
修正
Intent intent = new Intent(this, RoomInfoActivity.class);
到
Intent intent = new Intent(RoomListActivity.this, RoomInfoActivity.class);
这个错误是因为由这
您参考OnClickListener。问题是固定的,如果你指的是活动的这
。第二个错误是一样的 - 错误的参考。只是删除这
,和startActivity()方法将封闭类中被搜索。
The error is because by this
you refer to OnClickListener. The problem is fixed, if you refer to the Activity's this
. The second error is the same - wrong reference. Just remove this
, and startActivity() method will be searched within the enclosing class too.
这篇关于onItemClick,意图,startActivity错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!