这是我的主要活动 请帮我 例如,当我触摸家庭秀活动家 IDE(Android Studio) http://flameit.ir/MainActivity.java
答案 0 :(得分:0)
在适配器中声明新变量
Context mContext;
替换你的适配器构造函数
MyAdapter(String Titles[], int Icons[], String Name, String Email, int Profile) {
mNavTitles = Titles;
mIcons = Icons;
name = Name;
email = Email;
profile = Profile;
}
以下
MyAdapter(String Titles[], int Icons[], String Name, String Email, int Profile,Context cntx) {
mNavTitles = Titles;
mIcons = Icons;
name = Name;
email = Email;
profile = Profile;
mContext=cntx;
}
初始化您的适配器
mAdapter = new MyAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE,MainActivity.this);
现在你要调用新活动的地方
Intent itt=new Intent(mContext,YourNew.class);
mContext.startActivity(itt);
如果你想在你的适配器下面的recycleview适配器上调用新活动
public ViewHolder(View itemView, int ViewType) {
super(itemView);
if (ViewType == TYPE_ITEM) {
textView = (TextView) itemView.findViewById(R.id.rowText);
imageView = (ImageView) itemView.findViewById(R.id.rowIcon);
Holderid = 1;
} else {
Name = (TextView) itemView.findViewById(R.id.name);
email = (TextView) itemView.findViewById(R.id.email);
profile = (ImageView) itemView.findViewById(R.id.circleView);
Holderid = 0;
}
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent itt=new Intent(mContext,YourNew.class);
mContext.startActivity(itt);
}
});
}