【发布时间】:2014-04-14 06:35:47
【问题描述】:
我的 Eclipse 在 switch 中给出了一条带有意图的错误消息:The constructor Intent (new Adapter.View.OnItemClickListener(){}, Class <UlohaShowerActivity>) is undefined
所有项目意图都可以,但这可以找到一个原因。我不知道这个说法有什么问题。我正在使用来自其他活动的这些意图,它工作得很好,活动在清单中并且......只有在这个开关和 OnItemClick 中才会出现错误。
这是我的活动代码,
public class HladajListActivity extends Activity
{
private DatabaseOp mDbHelper;
public static final String HOW = "how";
public static final String NAME = "name";
public static final String DATE = "date";
public static final String TYP = "typ";
int how;
String name;
String date;
int typ;
String username;
String nazov;
String datum;
ListView listview;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.hladaj);
Intent i = getIntent();
how = Integer.parseInt(i.getStringExtra(HOW));
name = i.getStringExtra(NAME);
date = i.getStringExtra(DATE);
typ = Integer.parseInt(i.getStringExtra(TYP));
listview = (ListView) findViewById(R.id.listHladaj);
mDbHelper = new DatabaseOp(this);
mDbHelper.open();
showUserSettings();
Cursor hladajCursor = mDbHelper.fetchAllFind(username, name, date, how, typ);
final HladajCursorAdapter adapter = new HladajCursorAdapter(this, hladajCursor);
listview.setAdapter(adapter);
if (listview.getCount()==0)
setContentView(R.layout.hladaj_empty);
listview.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int stlpec, long arg3)
{
// TODO Auto-generated method stub
Cursor cur = (Cursor) adapter.getItem(stlpec);
String typ = cur.getString(cur.getColumnIndex("typ"));
String odosli = cur.getString(cur.getColumnIndex("_id"));
switch (Integer.parseInt(typ))
{
case 0:
Intent intent = new Intent(this,UlohaShowerActivity.class);
intent.putExtra(UlohaShowerActivity.ODOSLI, odosli);
startActivity(intent);
break;
case 1:
Intent intent = new Intent(this,PredmetShowerActivity.class);
intent.putExtra(PredmetShowerActivity.ODOSLI, odosli);
startActivity(intent);
break;
case 2:
Intent intent = new Intent(this,PoznamkaShowerActivity.class);
intent.putExtra(PoznamkaShowerActivity.ODOSLI, odosli);
startActivity(intent);
break;
}
}
});
}
@Override
public void onPause()
{
super.onPause();
mDbHelper.close();
}
private void showUserSettings()
{
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
username = sharedPrefs.getString("prefUsername", "NULL");
}
}
【问题讨论】:
-
尝试这种方式
Intent intent = new Intent(HladajListActivity .this,UlohaShowerActivity.class);也适用于所有其他情况 -
您是否在 manifest.xml 中添加了该活动?
标签: android android-intent android-activity switch-statement