Android 如何在pageradpter中完成活动?

Android 如何在pageradpter中完成活动?,android,android-pageradapter,Android,Android Pageradapter,我使用pageradapter,在这里我有一个按钮,可以调用其他功能。我可以在调用secondactivity后完成PagePractivity吗。我的pageradapter代码在下面。类型new View.OnClickListener()的方法finish()未定义{} 谢谢 公共类ImageAdapterPromers扩展了PagerAdapter{ 语境; ArrayList文本数组; arraylisturlarray; ArrayList位图数组; 图像视图图像视图; TextVi

我使用pageradapter,在这里我有一个按钮,可以调用其他功能。我可以在调用secondactivity后完成PagePractivity吗。我的pageradapter代码在下面。类型new View.OnClickListener()的方法finish()未定义{} 谢谢

公共类ImageAdapterPromers扩展了PagerAdapter{
语境;
ArrayList文本数组;
arraylisturlarray;
ArrayList位图数组;
图像视图图像视图;
TextView textreklama1;
按钮btnZoznam;
公共活动;
私有int[]GalImages=新int[]{
//来自资源文件夹的图像。
R.drawable.one,
R.drawable.2,
三号
};
ImageAdapterFromRes(上下文上下文、ArrayList textArray、ArrayList urlArray、ArrayList bitmapArray){
this.context=context;
this.textary=textArray;
this.urlArray=urlArray;
this.bitmapArray=bitmapArray;
}
@凌驾
public int getCount(){
返回GalImages.length;
}
公共对象实例化项(视图组集合,int位置){
LayoutInflater充气器=(LayoutInflater)集合。getContext()
.getSystemService(上下文布局\充气机\服务);
视图=充气机。充气(R.layout.reklamator_new,null);
imageView=(imageView)view.findViewById(R.id.imgreklama1);
setImageBitmap(bitmapArray.get(位置));
textreklama1=(TextView)view.findViewById(R.id.textreklama1);
textreklama1.setText(textary.get(position.toString());
btnZoznam=(按钮)view.findviewbyd(R.id.btnZoznam);
btnZoznam.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Intent i=新的Intent(v.getContext(),SecondActivity.class);
Bundle extras=新Bundle();
额外输入字符串(“cat”、“1”);
i、 临时演员(临时演员);
背景。起始触觉(i);
//如何完成?
}
});
((视图组)集合).addView(视图,0);
返回视图;
}
@凌驾
公共项目(视图组arg0、int arg1、对象arg2){
移除视图((视图)arg2);
}
@凌驾
公共布尔值isViewFromObject(视图arg0,对象arg1){
返回arg0==((视图)arg1);
}
}

您可以通过演员阵容完成活动:

((Activity) context).finish();

您可以通过强制转换来完成活动:

((Activity) context).finish();

您可以通过强制转换来完成活动:

((Activity) context).finish();

您可以通过强制转换来完成活动:

((Activity) context).finish();

我建议该活动处理它所做的事情(稍后您可以将其放在片段中)

您可以简单地访问
((活动)上下文).finish()
,但我倾向于这样做

下面是一个简短的片段:

public class ImageAdapterFromRes extends PagerAdapter {

    OnPagerItemSelected mListener;
    Context context;

    ImageAdapterFromRes(Context context, ArrayList<String> textArray, ArrayList<String> urlArray, ArrayList<Bitmap> bitmapArray,
        OnPagerItemSelected listener
        ){

        this.context=context;
        this.textArray=textArray;
        this.urlArray=urlArray;
        this.bitmapArray=bitmapArray;

        this.mListener = listener;
    }

    @Override
    public int getCount() {
        return GalImages.length;
    }

    public Object instantiateItem(ViewGroup collection, int position) {

         btnZoznam.setOnClickListener(new View.OnClickListener() {

             @Override
             public void onClick(View v) {

                 Intent i = new Intent(v.getContext(), SecondActivity.class);
                 Bundle extras = new Bundle();
                 extras.putString("cat", "1");
                 i.putExtras(extras);
                 context.startActivity(i);
                 //finish(); ???????? HOW FINISH ?

                 mListener.pagerItemSelected();
             }
         });
     }

     public interface OnPagerItemSelected {
         void pagerItemSelected();
     }


}

我建议该活动处理它所做的事情(稍后您可以将其放在片段中)

您可以简单地访问
((活动)上下文).finish()
,但我倾向于这样做

下面是一个简短的片段:

public class ImageAdapterFromRes extends PagerAdapter {

    OnPagerItemSelected mListener;
    Context context;

    ImageAdapterFromRes(Context context, ArrayList<String> textArray, ArrayList<String> urlArray, ArrayList<Bitmap> bitmapArray,
        OnPagerItemSelected listener
        ){

        this.context=context;
        this.textArray=textArray;
        this.urlArray=urlArray;
        this.bitmapArray=bitmapArray;

        this.mListener = listener;
    }

    @Override
    public int getCount() {
        return GalImages.length;
    }

    public Object instantiateItem(ViewGroup collection, int position) {

         btnZoznam.setOnClickListener(new View.OnClickListener() {

             @Override
             public void onClick(View v) {

                 Intent i = new Intent(v.getContext(), SecondActivity.class);
                 Bundle extras = new Bundle();
                 extras.putString("cat", "1");
                 i.putExtras(extras);
                 context.startActivity(i);
                 //finish(); ???????? HOW FINISH ?

                 mListener.pagerItemSelected();
             }
         });
     }

     public interface OnPagerItemSelected {
         void pagerItemSelected();
     }


}

我建议该活动处理它所做的事情(稍后您可以将其放在片段中)

您可以简单地访问
((活动)上下文).finish()
,但我倾向于这样做

下面是一个简短的片段:

public class ImageAdapterFromRes extends PagerAdapter {

    OnPagerItemSelected mListener;
    Context context;

    ImageAdapterFromRes(Context context, ArrayList<String> textArray, ArrayList<String> urlArray, ArrayList<Bitmap> bitmapArray,
        OnPagerItemSelected listener
        ){

        this.context=context;
        this.textArray=textArray;
        this.urlArray=urlArray;
        this.bitmapArray=bitmapArray;

        this.mListener = listener;
    }

    @Override
    public int getCount() {
        return GalImages.length;
    }

    public Object instantiateItem(ViewGroup collection, int position) {

         btnZoznam.setOnClickListener(new View.OnClickListener() {

             @Override
             public void onClick(View v) {

                 Intent i = new Intent(v.getContext(), SecondActivity.class);
                 Bundle extras = new Bundle();
                 extras.putString("cat", "1");
                 i.putExtras(extras);
                 context.startActivity(i);
                 //finish(); ???????? HOW FINISH ?

                 mListener.pagerItemSelected();
             }
         });
     }

     public interface OnPagerItemSelected {
         void pagerItemSelected();
     }


}

我建议该活动处理它所做的事情(稍后您可以将其放在片段中)

您可以简单地访问
((活动)上下文).finish()
,但我倾向于这样做

下面是一个简短的片段:

public class ImageAdapterFromRes extends PagerAdapter {

    OnPagerItemSelected mListener;
    Context context;

    ImageAdapterFromRes(Context context, ArrayList<String> textArray, ArrayList<String> urlArray, ArrayList<Bitmap> bitmapArray,
        OnPagerItemSelected listener
        ){

        this.context=context;
        this.textArray=textArray;
        this.urlArray=urlArray;
        this.bitmapArray=bitmapArray;

        this.mListener = listener;
    }

    @Override
    public int getCount() {
        return GalImages.length;
    }

    public Object instantiateItem(ViewGroup collection, int position) {

         btnZoznam.setOnClickListener(new View.OnClickListener() {

             @Override
             public void onClick(View v) {

                 Intent i = new Intent(v.getContext(), SecondActivity.class);
                 Bundle extras = new Bundle();
                 extras.putString("cat", "1");
                 i.putExtras(extras);
                 context.startActivity(i);
                 //finish(); ???????? HOW FINISH ?

                 mListener.pagerItemSelected();
             }
         });
     }

     public interface OnPagerItemSelected {
         void pagerItemSelected();
     }


}

谢谢,运行良好,但我建议可能是下一个答案。谢谢,运行良好,但我建议可能是下一个答案。谢谢,运行良好,但我建议可能是下一个答案。谢谢,运行良好,但我建议可能是下一个答案。我必须在MyActivity public void pagerItemSelected(){finish();}中编辑此行我必须在MyActivity public void pagerItemSelected()中编辑此行{finish();}我必须在MyActivity public void pagerItemSelected()中编辑此行{finish();}我必须在MyActivity public void pagerItemSelected()中编辑此行{finish();}