Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical" >
  5.  
  6. <TextView
  7. android:id="@+id/my_text_view"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_margin="10dp"
  11. android:text="test" />
  12.  
  13. <ImageView
  14. android:layout_width="fill_parent"
  15. android:layout_height="wrap_content"
  16. android:adjustViewBounds="true" />
  17.  
  18. </LinearLayout>
  19.  
  20. @Override
  21. public void onBindViewHolder(ViewHolder holder, int position) {
  22. holder.mTextView.setText(mDataset[position]);
  23. holder.mImageView.setImageURI(Uri.parse("file://" + mMediaStorageDir.getPath() + "/" + mDataset[position]));
  24. }
  25.  
  26. package com.shustikov.android;
  27.  
  28. public class ItemData {
  29.  
  30. private String title;
  31. private int imageUrl;
  32.  
  33. public ItemData(String title,int imageUrl){
  34.  
  35. this.title = title;
  36. this.imageUrl = imageUrl;
  37. }
  38.  
  39. public String getTitle() {
  40. return title;
  41. }
  42.  
  43. public int getImageUrl() {
  44. return imageUrl;
  45. }
  46. }
  47.  
  48. package com.shustikov.android;
  49.  
  50. import android.support.v7.widget.RecyclerView;
  51. import android.view.LayoutInflater;
  52. import android.view.View;
  53. import android.view.ViewGroup;
  54. import android.widget.ImageView;
  55. import android.widget.TextView;
  56.  
  57. public class RecyclerViewExampleAdapter extends RecyclerView.Adapter<RecyclerViewExampleAdapter.ViewHolder> {
  58. private ItemData[] itemsData;
  59.  
  60. public RecyclerViewExampleAdapter(ItemData[] itemsData) {
  61. this.itemsData = itemsData;
  62. }
  63.  
  64. @Override
  65. public RecyclerViewExampleAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
  66. int viewType) {
  67. View itemLayoutView = LayoutInflater.from(parent.getContext())
  68. .inflate(R.layout.item_layout, null);
  69.  
  70. ViewHolder viewHolder = new ViewHolder(itemLayoutView);
  71. return viewHolder;
  72. }
  73.  
  74. @Override
  75. public void onBindViewHolder(ViewHolder viewHolder, int position) {
  76.  
  77. viewHolder.txtViewTitle.setText(itemsData[position].getTitle());
  78. viewHolder.imgViewIcon.setImageResource(itemsData[position].getImageUrl());
  79. }
  80.  
  81. public static class ViewHolder extends RecyclerView.ViewHolder {
  82.  
  83. public TextView txtViewTitle;
  84. public ImageView imgViewIcon;
  85.  
  86. public ViewHolder(View itemLayoutView) {
  87. super(itemLayoutView);
  88. txtViewTitle = (TextView) itemLayoutView.findViewById(R.id.item_title);
  89. imgViewIcon = (ImageView) itemLayoutView.findViewById(R.id.item_icon);
  90. }
  91. }
  92.  
  93.  
  94. @Override
  95. public int getItemCount() {
  96. return itemsData.length;
  97. }
  98. }
  99.  
  100. public void bindPhoto(Photo photo) {
  101. mPhoto = photo;
  102. mPhotoFile=PhotoLab.get(getActivity()).getPhotoFile(mPhoto);
  103. Uri uri=Uri.fromFile(mPhotoFile);
  104.  
  105. if(mPhotoFile==null || !mPhotoFile.exists()){
  106. int imgdrawable=R.drawable.ic_action_name3;
  107. mThumbnail.setImageDrawable(getResources().getDrawable(imgdrawable));
  108. } else {
  109. Picasso.with(getActivity()).load(uri).fit().into(mThumbnail);
  110. }
  111.  
  112.  
  113. mTitleTextView.setText(mPhoto.getTitle());
  114. String dateFormat = "EEE, MMM dd";
  115. dateString = DateFormat.format(dateFormat, mPhoto.getDate()).toString();
  116. mDateTextView.setText(dateString);
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement