gpt4 book ai didi

android - 在 swipeview 中设置 StartActivity

转载 作者:行者123 更新时间:2023-11-29 01:22:36 25 4
gpt4 key购买 nike

我正在尝试制作一个带有按钮的滑动 View ,只要单击该按钮,它就会打开第二个 Activity ,但我无法在点击监听器中设置 setActivity 这是我的代码。将进行哪些更改我在我的寻呼机适配器中做

package com.example.neelaysrivastava.imageswipe;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


public class CustomeSwipeAdapter extends PagerAdapter {
private int[] image_resource={R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4,R.drawable.img5,R.drawable.img6} ;
private Context ctx;
private LayoutInflater layoutInflater;
public CustomeSwipeAdapter(Context ctx){
this.ctx=ctx;
}

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

@Override
public boolean isViewFromObject(View view, Object object) {
return (view==(LinearLayout)object );
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater =(LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view =layoutInflater.inflate(R.layout.second,container,false);
ImageView imageView =(ImageView)item_view.findViewById(R.id.imageView);
Button button=(Button)item_view.findViewById(R.id.button);
imageView.setImageResource(image_resource[position]);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});
container.addView(item_view);
return item_view;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}

最佳答案

只需实现 interface 并将其注册到按钮点击监听器中,然后在您的 Activity 中实现该接口(interface),并将该接口(interface)的实例传递给您的 CustomeSwipeAdapter 构造函数。

关于android - 在 swipeview 中设置 StartActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35913799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com