我正在尝试研究如何开发我的第一个应用程序但是eclipse会给我发错误 当我尝试编译此代码时,“构造函数意图未定义”:
package com.baruckis.SlidingMenuImplementation.FromClass;
import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;
import com.baruckis.SlidingMenuImplementation.R;
import com.baruckis.SlidingMenuImplementation.SlidingMenuListItem;
import com.baruckis.SlidingMenuImplementation.prova;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
public class SlidingMenuBuilderBase {
protected Activity activity;
protected SlidingMenu menu = null;
public void createSlidingMenu(Activity activity) {
this.activity = activity;
menu = new SlidingMenu(activity);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.sliding_menu_shadow_width);
menu.setShadowDrawable(R.drawable.sliding_menu_shadow);
menu.setBehindOffsetRes(R.dimen.sliding_menu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(activity, SlidingMenu.SLIDING_WINDOW);
menu.setMenu(R.layout.sliding_menu_frame);
SlidingMenuListFragment slidingMenuListFragment = new SlidingMenuListFragment();
slidingMenuListFragment.setMenuBuilder(this);
activity.getFragmentManager().beginTransaction()
.replace(R.id.sliding_menu_frame, slidingMenuListFragment)
.commit();
}
public SlidingMenu getSlidingMenu() {
return menu;
}
public void onListItemClick(SlidingMenuListItem selectedSlidingMenuListItem) {
CharSequence text;
switch (selectedSlidingMenuListItem.Id) {
case R.slidingmenu.list_item_municipio_id:
Intent ii = new Intent(this, prova.class);
startActivity(ii);
finish();
break;
case R.slidingmenu.list_item_basic_id:
text = "Clicked item “"
+ selectedSlidingMenuListItem.Name
+ "”. "
+ activity
.getString(R.string.toast_sliding_menu_custom_action);
Toast.makeText(activity, text, Toast.LENGTH_LONG).show();
break;
default:
text = "Clicked item. "
+ activity
.getString(R.string.toast_sliding_menu_no_action_default);
Toast.makeText(activity, text, Toast.LENGTH_LONG).show();
break;
}
}
}
我已经尝试在其他线程中寻找解决方案,但我找不到适合我的方法!
答案 0 :(得分:2)
更改
Intent ii = new Intent(this, prova.class);
到
Intent ii = new Intent(activity, prova.class);
您需要Activity Context
才能启动Activity
,因为您的课程未延伸Activity
,您需要使用传递给它的activity
参数
答案 1 :(得分:1)
这是因为SlidingMenuBuilderBase
不是Context
,就像Activity
一样。由于您持有Activity
数据成员中的activity
个实例,因此可以使用this
替换Intent
构造函数中的activity
。