我正在浏览我的第一个viewpager示例。它由两个fragement组成,一个带有textview,另一个带有imageview。以下是带有imageview的片段代码:
public class ImageFragment extends Fragment {
private final int imageResourceId ;
public ImageFragment (int imageResourceId)
{
this.imageResourceId = imageResourceId;
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.e("Test","Hello");
}
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState)
{
View view = inflater.inflate(R.layout.image_layout, container,false);
ImageView imageView = (ImageView)view.findViewById(R.id.imageView1);
ImageView.setImageResource(imageResourceId);
return view;
}
}
如何为此imageview实施点击处理程序?
答案 0 :(得分:1)
你的意思是onClickListener
?
您可以设置:
imageView.setClickable(true);
imageView.setOnClickListener(new OnClickListener{...});
像往常一样,它无法掌握它是否在碎片或其他任何东西。