2017-02-20 160 views
0

我试图使用粒子系统从下面的链接 https://github.com/plattysoft/Leonids粒子系统

   ParticleSystem ps = new ParticleSystem(holder.itemView.getContext(), 50, R.drawable.emoji_1f358, 1000); 
       ps.setSpeedRange(0.1f, 0.25f); 
       ps.setScaleRange(0.7f, 1.3f); 
       ps.setSpeedRange(0.1f, 0.25f); 
       ps.setAcceleration(0.0001f, 90); 
       ps.setRotationSpeedRange(90, 180); 
       ps.setFadeOut(200, new AccelerateInterpolator()); 
       ps.emit(v, 100) 

我尝试使用它在MyAdapter文件在下面的功能: -

public void onBindViewHolder(final MyHolderCHAT holder, final int position) { 
} 

这是给我一个构建错误,如下所示: -

Error:(1824, 41) error: no suitable constructor found for ParticleSystem(Context,int,int,int) constructor ParticleSystem.ParticleSystem(ViewGroup,int,Drawable,long) is not applicable (argument mismatch; Context cannot be converted to ViewGroup) constructor ParticleSystem.ParticleSystem(Activity,int,int,long) is not applicable (argument mismatch; Context cannot be converted to Activity) constructor ParticleSystem.ParticleSystem(Activity,int,Drawable,long) is not applicable (argument mismatch; Context cannot be converted to Activity) constructor ParticleSystem.ParticleSystem(Activity,int,Bitmap,long) is not applicable (argument mismatch; Context cannot be converted to Activity) constructor ParticleSystem.ParticleSystem(Activity,int,AnimationDrawable,long) is not applicable (argument mismatch; Context cannot be converted to Activity)

这是我的代码adapte r:

public class MyAdapterCHAT extends RecyclerView.Adapter<MyHolderCHAT> { 

    Context c; 
    Activity activity; 
    int click=0; 
    int img_pos; 
    boolean isPlaying=false; 
    static MediaPlayer mp; 
    int curr_pos; 
    ViewGroup vg; 
    CountDownTimer cT; 
    int total; 
    String DBname; 
    //private FullScreenImageAdapter adapter; 

    ArrayList<String> path; 
    private ViewPager viewPager; 
    String react; 
    ArrayList<String> pagerListItems; 
    int progress=0; 
    ArrayList<DATA_CONTACT_CHAT> data_contact,filterlist22; 
    // private final ItemClickListener listener; 

    public MyAdapterCHAT(Context c, ArrayList<DATA_CONTACT_CHAT> data_contact) { 
     this.c = c; 
     this.data_contact = data_contact; 
     this.filterlist22=data_contact; 
     // this.listener=listener; 
    } 


    @Override 
    public MyHolderCHAT onCreateViewHolder(ViewGroup parent, int viewType) { 

     View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.chatinputlayout,parent,false); 

     MyHolderCHAT myHolderCHAT=new MyHolderCHAT(view); 

     //this.vg=parent; 

     return myHolderCHAT; 
    } 


@Override 
    public void onBindViewHolder(final MyHolderCHAT holder, final int position) { 
     //BIND DATA 

holder.hi5.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       if(holder.counter_hi5.getText().toString().contains("remaining:")) 
       { 
        if (data_contact.get(position).getSender_name().equals(data_contact.get(position).getCurrent_user())) { 

         Vibrator vibe = (Vibrator) holder.itemView.getContext().getSystemService(Context.VIBRATOR_SERVICE); 
         vibe.vibrate(100); 
         Toast.makeText(c, " \uD83C\uDFFB Ohh..Wait for " + data_contact.get(position).getSecond_user() + " To Hi5 You..", Toast.LENGTH_SHORT).show(); 

        } else { 
         cT.cancel(); 
         holder.counter_hi5.setText(" \uD83D\uDE00 You got a High Five from " + data_contact.get(position).getSecond_user()); 

        ParticleSystem ps = new ParticleSystem(holder.itemView.getContext(), 50, R.drawable.emoji_1f358, 1000); 
        ps.setSpeedRange(0.1f, 0.25f); 
        ps.setScaleRange(0.7f, 1.3f); 
        ps.setSpeedRange(0.1f, 0.25f); 
        ps.setAcceleration(0.0001f, 90); 
        ps.setRotationSpeedRange(90, 180); 
        ps.setFadeOut(200, new AccelerateInterpolator()); 
        ps.emit(v, 100); 

        } 
       } 
       else { 

       } 
      } 
     }); 



} 
+0

好像'ParticleSystem'并不需要一个'Context'。它的构造函数调用中第一个参数可以是“Activity”或“ViewGroup”。你的'ViewHolder'中有'ViewGroup'吗? –

+0

我应该输入什么...然后请帮助 –

+0

你在ViewHolder中有一个'ViewGroup'吗? –

回答

0

堆栈跟踪正在给出发生了什么。您传递的参数没有构造函数。

您可以尝试其他方法来实例化它。

例如:new ParticleSystem(ViewGroup, int, Drawable , long)

所以,

Context ctx = holder.itemView.getContext() 
ViewGroup vg = (ViewGroup) holder.itemView.getParent(); 
Drawable drawable = ContextCompat.getDrawable(ctx, R.drawable.emoji_1f358); 
ParticleSystem ps = new ParticleSystem(vg, 50, drawable, 1000L); 
ps.setSpeedRange(0.1f, 0.25f); 
ps.setScaleRange(0.7f, 1.3f); 
ps.setSpeedRange(0.1f, 0.25f); 
ps.setAcceleration(0.0001f, 90); 
ps.setRotationSpeedRange(90, 180); 
ps.setFadeOut(200, new AccelerateInterpolator()); 
ps.emit(v, 100) 
+0

错误>>> NullPointerException:试图调用虚拟方法'布尔android.support.v7.widget.RecyclerView $ ViewHolder.shouldIgnore()'对空引用对象在 –

+0

有人请帮忙.. –