我想从此基本适配器开始一个新活动。
public class EfficientAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<ComptePost> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
public Boolean isActusAstuce;
public static int flag = 0, counter=0;
private Context context;
public EfficientAdapter(Context context) {
this.context = context;
}
NVirementEmmeteur main;
int num = 0;
ViewHolder holder;
static String src;
public EfficientAdapter(Activity a, ArrayList<ComptePost> d) {
activity = a;
data = d;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// imageLoader = new ImageLoader(activity.getApplicationContext());
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public EfficientAdapter(NVirementEmmeteur m) {
main = m;
}
@Override
public int getCount() {
return data.toArray().length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView one;
public TextView two;
public TextView three;
public ImageView image;
public RelativeLayout relative_layout;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
holder.relative_layout.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.getContext().startActivity(new Intent(context, NVirementEmmeteur.class));
}
});
return vi;
}
}
我试过了
context.startActivity(new Intent(context, NVirementEmmeteur.class));
和
v.getContext().startActivity(new Intent(context, NVirementEmmeteur.class));
但它强制关闭我的应用程序。
onclicklistener()
意图应该在来自列表适配器的内部启动。有人能告诉我如何从我的efficientadapter.class 启动一个意图吗?
这是我的 logcat 输出:
04-11 10:07:50.878: E/AndroidRuntime(11179): 致命异常: main 04-11 10:07:50.878: E/AndroidRuntime(11179): java.lang.NullPointerException 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 android.content.ComponentName.(ComponentName.java:75) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 android.content.Intent.(Intent.java:2863 ) 04-11 10:07:50.878: E/AndroidRuntime(11179): at.adapter.EfficientAdapter$1.onClick(EfficientAdapter.java:141) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 android .view.View.performClick(View.java:2538) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 android.view.View$PerformClick.run(View.java:9152) 04-11 10 :07:50.878: E/AndroidRuntime(11179): 在 android.os.Handler.handleCallback(Handler.java:587) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 android.os.Handler。调度消息(处理程序.java:92) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 android.os.Looper.loop(Looper.java:130) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在android.app.ActivityThread.main(ActivityThread.java:3687) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 java.lang.reflect.Method.invokeNative(Native Method) 04-11 10:07 :50.878: E/AndroidRuntime(11179): at java.lang.reflect.Method.invoke(Method.java:507) 04-11 10:07:50.878: E/AndroidRuntime(11179): at com.android.internal。 os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 04-11 10:07:50.878: E/AndroidRuntime(11179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 04 -11 10:07:50.878:E/AndroidRuntime(11179):在 dalvik.system.NativeStart.main(本机方法)878: E/AndroidRuntime(11179): 在 android.app.ActivityThread.main(ActivityThread.java:3687) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 java.lang.reflect.Method.invokeNative (本机方法) 04-11 10:07:50.878: E/AndroidRuntime(11179): at java.lang.reflect.Method.invoke(Method.java:507) 04-11 10:07:50.878: E/AndroidRuntime( 11179): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 com.android.internal.os.ZygoteInit .main(ZygoteInit.java:600) 04-11 10:07:50.878: E/AndroidRuntime(11179): at dalvik.system.NativeStart.main(Native Method)878: E/AndroidRuntime(11179): 在 android.app.ActivityThread.main(ActivityThread.java:3687) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 java.lang.reflect.Method.invokeNative (本机方法) 04-11 10:07:50.878: E/AndroidRuntime(11179): at java.lang.reflect.Method.invoke(Method.java:507) 04-11 10:07:50.878: E/AndroidRuntime( 11179): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 04-11 10:07:50.878: E/AndroidRuntime(11179): 在 com.android.internal.os.ZygoteInit .main(ZygoteInit.java:600) 04-11 10:07:50.878: E/AndroidRuntime(11179): at dalvik.system.NativeStart.main(Native Method)E/AndroidRuntime(11179): at java.lang.reflect.Method.invoke(Method.java:507) 04-11 10:07:50.878: E/AndroidRuntime(11179): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:842) 04-11 10:07:50.878: E/AndroidRuntime(11179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 04-11 10 :07:50.878:E / AndroidRuntime(11179):在dalvik.system.NativeStart.main(本机方法)E/AndroidRuntime(11179): at java.lang.reflect.Method.invoke(Method.java:507) 04-11 10:07:50.878: E/AndroidRuntime(11179): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:842) 04-11 10:07:50.878: E/AndroidRuntime(11179): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 04-11 10 :07:50.878:E / AndroidRuntime(11179):在dalvik.system.NativeStart.main(本机方法)