我有这个图像视图,
这个图像是由具有许多图像的回收者视图改变的,问题是如何知道我点击了哪个图像!并且我有一个整数值来将它添加到for循环任何想法?
这是此活动的代码
public class ListViewDetailsFragment extends Fragment {
ImageView AppImage;
TextView AppName,AppArtist,AppContentType,AppRights,AppCategory,AppRealseDate,AppSammary;
ImageButton AppLink;
Context context;
public ListViewDetailsFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_list_view_details, container, false);}
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AppImage = (ImageView) getView().findViewById(R.id.imageView);
AppName = (TextView) getView().findViewById(R.id.textname);
AppArtist = (TextView) getView().findViewById(R.id.textartest);
AppContentType = (TextView) getView().findViewById(R.id.textcontent);
AppRights = (TextView) getView().findViewById(R.id.textrights);
AppCategory = (TextView) getView().findViewById(R.id.textCategory);
AppRealseDate = (TextView) getView().findViewById(R.id.textRelease);
AppSammary = (TextView) getView().findViewById(R.id.textSummary);
AppLink = (ImageButton) getView().findViewById(R.id.imageButton);
String name = getActivity().getIntent().getExtras().getString("App_name");
final String image = getActivity().getIntent().getExtras().getString("App_image");
String artist = getActivity().getIntent().getExtras().getString("App_artist");
String contentType = getActivity().getIntent().getExtras().getString("App_ContentType");
String rights = getActivity().getIntent().getExtras().getString("App_Rights");
String category = getActivity().getIntent().getExtras().getString("App_Category");
String realse = getActivity().getIntent().getExtras().getString("App_ReleaseDate");
final String link = getActivity().getIntent().getExtras().getString("App_link");
String sammary = getActivity().getIntent().getExtras().getString("App_summary");
AppName.setText(name);
final AppShowModule appShowModule = new AppShowModule();
AppArtist.setText(artist);
AppContentType.setText(contentType);
AppRights.setText(rights);
AppCategory.setText(category);
AppRealseDate.setText(realse);
AppSammary.setText(sammary);
Picasso.with(context).load(image).into(AppImage);
AppLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AppImage.setTag("id that you get from extras");
Intent intent = new Intent(getActivity().getBaseContext(),
WebView.class);
intent.putExtra("App_link", link);
getActivity().startActivity(intent);}});
AppImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity().getBaseContext(), ImageList.class);
getActivity().startActivity(intent);
}});}}
答案 0 :(得分:1)
您应该在onCreateViewHolder
方法中为RecyclerView的每个ImageView设置一个OnClickListener(在您的适配器中)。
您可以使用viewHolder.getAdapterPosition()
来获取商品的位置。