我的代码:
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();
}
});
}
}我在以下几行都有错误:
Intent intent = new Intent(this, RoomInfoActivity.class);和
this.startActivity(intent);我不太清楚为什么会出现这些错误,这些错误在编辑器中的确切输出是:
构造函数意图(新的undefined"
我是一个Android新手,所以请考虑到这一点,但是我已经学习Java大约一年了。
发布于 2011-05-16 11:38:42
修复
Intent intent = new Intent(this, RoomInfoActivity.class);至
Intent intent = new Intent(RoomListActivity.this, RoomInfoActivity.class);这个错误是因为this引用了OnClickListener。如果您引用活动的this,问题就解决了。第二个错误是同样错误的引用。只需删除this,startActivity()方法也将在封闭类中进行搜索。
发布于 2011-05-16 11:40:18
尝尝这个
Intent intent = new Intent(RoomListActivity.this, RoomInfoActivity.class);
intent.putExtra("entry",roominfo);
RoomListActivity.this.startActivity(intent);https://stackoverflow.com/questions/6016793
复制相似问题