Android 如何在自定义RecyclerView适配器中使用startActivity(intent)启动新活动?
我有一个CustomRecycleServiceAdapter.class文件,我在其中实现了以下方法Android 如何在自定义RecyclerView适配器中使用startActivity(intent)启动新活动?,android,android-recyclerview,onitemclicklistener,Android,Android Recyclerview,Onitemclicklistener,我有一个CustomRecycleServiceAdapter.class文件,我在其中实现了以下方法 public void onBindViewHolder(RecyclerViewHolder viewHolder, int position) { viewHolder.title.setText(mData.get(position).text); //viewHolder.icon.setBackgroundColor(Color.parseColor(mData.ge
public void onBindViewHolder(RecyclerViewHolder viewHolder, int position)
{
viewHolder.title.setText(mData.get(position).text);
//viewHolder.icon.setBackgroundColor(Color.parseColor(mData.get(position).color));
viewHolder.setClickListener(new RecyclerViewHolder.ClickListener(){
@Override
public void onClick(View v, int position, boolean isLongClick) {
if (isLongClick) {
// View v at position pos is long-clicked.
Toast.makeText(v.getContext(), "Hey you just hit item" + position, Toast.LENGTH_SHORT).show();
}else {
// View v at position pos is clicked.
//how to start a new activity here
Toast.makeText(v.getContext(),"Hey you just hit item" + position,Toast.LENGTH_SHORT).show();
}
}
});
}
那么我如何在上面的else块中启动新活动
集体课
public class Group extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//line no. 16 which is indicated in logcat
setContentView(R.layout.group);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
这是我的错误日志
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.trueblueoperator.samplerecyclerview/com.trueblueoperator.samplerecyclerview.Group}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.trueblueoperator.samplerecyclerview.Group.onCreate(Group.java:16)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
谢谢您的时间。您可以使用任何视图查看它。 getContext()方法提供了几乎所有的活动方法,因为活动扩展了上下文
v.getContext().startActivity(intent);
那么,目前面临的问题是什么?只需使用
v.getContext().startActivity(intent)
点击按钮即可启动活动我使用了此代码intent intent=new intent(v.getContext(),Group.class);v、 getContext().startActivity(意图);但它在AndroidManifest.xml
中不幸地添加了Group.class
,停止了应用程序?如果是,那么共享崩溃日志我已经在menifest中添加了类,但我仍然收到了相同的问题,并且我已经用崩溃日志更新了帖子