2016-10-12 6 views
-2

私はアンドロイド開発の新人です。私は、Need Employee、NeedCofounderなどの異なるカスタムビューを膨張させているrecyclerviewを持っています。 ソーシャルメディア上でこれらの投稿を共有する機能を追加しようとしていますが、私が理解できないのは、ユーザーが共有を選択した現在のビューを取得する方法です。すべてのレイアウトは、私はこのRecyclerView Item Layout現在のItemLayoutのスクリーンショットを撮る

public Bitmap takeScreenshot() { 

     // Cannot figure out how to get the current view 
     View rootView = ???? 
     rootView.setDrawingCacheEnabled(true); 
     return rootView.getDrawingCache(); 
    } 

SharePostボタンのようにスクリーンショットを取るしようとしています

異なるxmlファイルを持っているあなたに

package com.devs.bevy.homeScreen.holders; 
import android.support.annotation.Nullable; 
import android.support.v7.widget.AppCompatCheckBox; 
import android.support.v7.widget.AppCompatImageView; 
import android.support.v7.widget.AppCompatTextView; 
import android.support.v7.widget.RecyclerView; 
import android.view.View; 
import android.widget.ProgressBar; 
import android.widget.RelativeLayout; 

import com.devs.bevy.R; 
import com.facebook.drawee.view.SimpleDraweeView; 

import butterknife.BindView; 
import butterknife.ButterKnife; 
import de.hdodenhof.circleimageview.CircleImageView; 

public class BevyPostViewHolder { 

    public static class MainHolder extends RecyclerView.ViewHolder{ 
     public @Nullable @BindView(R.id.userImage) CircleImageView userImage; 
     public @Nullable @BindView(R.id.userName) AppCompatTextView userName; 
     public @Nullable @BindView(R.id.postTime) AppCompatTextView postTime; 
     public @Nullable @BindView(R.id.postType) AppCompatTextView postType; 
     public @Nullable @BindView(R.id.btnAddToWishList) AppCompatCheckBox btnAddToWishList; 
     public @Nullable @BindView(R.id.messageWindow) AppCompatImageView messageWindow; 
     public @Nullable @BindView(R.id.commentWindow) AppCompatImageView commentWindow; 
     public @Nullable @BindView(R.id.commentCount) AppCompatTextView commentCount; 
     public @Nullable @BindView(R.id.markDoneUndone) AppCompatCheckBox markDoneUndone; 
     public @Nullable @BindView(R.id.deletePost) AppCompatImageView deletePost; 
     public @Nullable @BindView(R.id.sharePost) AppCompatImageView sharePost; 

     public MainHolder(View itemView) { 
      super(itemView); 
     } 
    } 

    public static class NeedCoFounder extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.experience) AppCompatTextView experience; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.equity) AppCompatTextView equity; 
     public @BindView(R.id.salary) AppCompatTextView salary; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public NeedCoFounder(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class NeedEmployee extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.experience) AppCompatTextView experience; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.equity) AppCompatTextView equity; 
     public @BindView(R.id.salary) AppCompatTextView salary; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public NeedEmployee(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class NeedIntern extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.stipend) AppCompatTextView stipend; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public NeedIntern(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class NeedFreelancer extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.experience) AppCompatTextView experience; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.price) AppCompatTextView price; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public NeedFreelancer(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class NeedOffice extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.type) AppCompatTextView type; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.description) AppCompatTextView description; 
     public @BindView(R.id.price) AppCompatTextView price; 

     public NeedOffice(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class NeedEntities extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.type) AppCompatTextView type; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.description) AppCompatTextView description; 
     public @BindView(R.id.price) AppCompatTextView price; 
     public @BindView(R.id.entitiesName) AppCompatTextView entitiesName; 

     public NeedEntities(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class NeedMentor extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.speciality) AppCompatTextView speciality; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public NeedMentor(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class OfferCoFounder extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.experience) AppCompatTextView experience; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public OfferCoFounder(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class OfferEmployee extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.experience) AppCompatTextView experience; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.description) AppCompatTextView description; 
     public @BindView(R.id.salary) AppCompatTextView salary; 

     public OfferEmployee(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class OfferIntern extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.stipend) AppCompatTextView stipend; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public OfferIntern(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 


    public static class OfferFreelancer extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.experience) AppCompatTextView experience; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.price) AppCompatTextView price; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public OfferFreelancer(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class OfferOffice extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.type) AppCompatTextView type; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.description) AppCompatTextView description; 
     public @BindView(R.id.price) AppCompatTextView price; 
     public @BindView(R.id.officeImage) SimpleDraweeView officeImage; 
     public @BindView(R.id.officeImageCount) AppCompatTextView officeImageCount; 
     public @BindView(R.id.imageLayout) RelativeLayout imageLayout; 

     public OfferOffice(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class OfferEntities extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.type) AppCompatTextView type; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.description) AppCompatTextView description; 
     public @BindView(R.id.price) AppCompatTextView price; 
     public @BindView(R.id.entitiesImage) SimpleDraweeView entitiesImage; 
     public @BindView(R.id.entitiesImageCount) AppCompatTextView entitiesImageCount; 
     public @BindView(R.id.imageLayout) RelativeLayout imageLayout; 

     public OfferEntities(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

     } 
    } 

    public static class OfferMentor extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.speciality) AppCompatTextView speciality; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public OfferMentor(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 


    public static class GpIdeaValidation extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.domain) AppCompatTextView domain; 
     public @BindView(R.id.title) AppCompatTextView title; 
     public @BindView(R.id.query) AppCompatTextView query; 

     public GpIdeaValidation(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class GpOptimizeCashFlow extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.title) AppCompatTextView title; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public GpOptimizeCashFlow(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpTeam extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.profile) AppCompatTextView profile; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public GpTeam(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class GpCompetitorAnalysis extends MainHolder { 

     public GpCompetitorAnalysis(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class GpProductPricing extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.currentPrice) AppCompatTextView currentPrice; 
     public @BindView(R.id.description) AppCompatTextView description; 
     public @BindView(R.id.shortDescription) AppCompatTextView shortDescription; 

     public GpProductPricing(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpProductReview extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.description) AppCompatTextView description; 
     public @BindView(R.id.website) AppCompatTextView website; 
     public @BindView(R.id.questions) AppCompatTextView questions; 

     public GpProductReview(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpBusinessModel extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.title) AppCompatTextView title; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public GpBusinessModel(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpMarketing extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.title) AppCompatTextView title; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public GpMarketing(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpCustomerVoices extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public GpCustomerVoices(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpMarketAnalysis extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.role1) AppCompatTextView role1; 
     public @BindView(R.id.location) AppCompatTextView location; 
     public @BindView(R.id.title) AppCompatTextView title; 
     public @BindView(R.id.when) AppCompatTextView when; 

     public GpMarketAnalysis(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpGetMotivation extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public GpGetMotivation(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpPivotAnalysis extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.brief) AppCompatTextView brief; 
     public @BindView(R.id.query) AppCompatTextView query; 
     public @BindView(R.id.title) AppCompatTextView title; 

     public GpPivotAnalysis(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpNeedInvestor extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.domains) AppCompatTextView domains; 
     public @BindView(R.id.title) AppCompatTextView title; 
     public @BindView(R.id.highLevelPitch) AppCompatTextView highLevelPitch; 
     public @BindView(R.id.description) AppCompatTextView description; 
     public @BindView(R.id.attachment) AppCompatTextView attachment; 

     public GpNeedInvestor(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpLegal extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.issues) AppCompatTextView issues; 
     public @BindView(R.id.query) AppCompatTextView query; 

     public GpLegal(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    public static class GpNetworking extends MainHolder { 
     public @BindView(R.id.role) AppCompatTextView role; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public GpNetworking(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

    public static class GpOther extends MainHolder { 
     public @BindView(R.id.title) AppCompatTextView title; 
     public @BindView(R.id.description) AppCompatTextView description; 

     public GpOther(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

/*PROGRESS BAR HOLDERS*/ 

    public static class ProgressViewHolder extends MainHolder { 
     public @BindView(R.id.progressBar) ProgressBar progressBar; 

     public ProgressViewHolder(View v) { 
      super(v); 
      try { 
       ButterKnife.bind(this, v); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 

に感謝

holder.sharePost.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Bitmap bitmap = takeScreenshot(); 
     } 
    }); 

答えて

1
holder.sharePost.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Bitmap bitmap = takeScreenshot(); 
//getAdapterPosition() will return position of a listview, from that list you can take holder.rootview 
      } 
     }); 
1

RecyclerViewAdapt er.class

private View.OnClickListener globalClickListener = new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       int selectedPosition = (int) v.getTag(); 
       // Save selectedPositions on list or do something    
       Bitmap bitmap = takeScreenshot(); 
      } 
     } 

RecyclerViewAdapter.onBindViewHolder

holder.sharePost.setTag(position); 
holder.sharePost.setOnClickListener(globalClickListener); 
+0

大丈夫、私が選択した位置を得たが、私はrootviewとして何を渡すか...閲覧rootViewは= ???? rootView.setDrawingCacheEnabled(true); return rootView.getDrawingCache(); –

+1

各行のスクリーンショットを撮りたいですか? 行のスクリーンショットを撮りたい場合は、 "v"を渡します。 プライベートView.OnClickListener globalClickListener = new View.OnClickListener(){ @Override パブリックボイドonClick(ビューv){ ビットマップbitmap = takeScreenshot(v); } } –

関連する問題