关键代码如下:
View functionsView = LayoutInflater.from(context).inflate(R.layout.popup_dianming_btn, null);functionsView.findViewById(R.id.voiceLL).setOnTouchListener(new       
SoundOnTouchUtilListener(context,data.get(groupPosition), functionsView.findViewById(R.id.voiceLL)));SoundOnTouchUtilListener如下public SoundOnTouchUtilListener(Context context,List<Visitor> listCard,View view){
this.listCard=listCard;
this.context=context;
this.view=view;
if(recordingSoundWin==null){
recordingSoundWin=new PopupWindow(LayoutInflater.from(context)
.inflate(R.layout.popupwindow_recordsound, null),
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
ImageView rocketImage = (ImageView)recordingSoundWin.getContentView().findViewById(R.id.rocketImage); 
rocketImage.setBackgroundResource(R.anim.imgchange); 
rocketAnimation=(AnimationDrawable)rocketImage.getBackground();
}
clockLL=(LinearLayout)recordingSoundWin.getContentView().findViewById(R.id.clockLL);
clockTextView=(TextView)recordingSoundWin.getContentView().findViewById(R.id.clockTextView);
}
public boolean onTouch(View v, MotionEvent event) {
//ACTION_MOVE=2, ACTION_UP = 1,ACTION_DOWN = 0;
if(listCard==null||listCard.size()==0){
Toast.makeText(context, R.string.nocards, Toast.LENGTH_SHORT).show();
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
recordingSoundWin.showAtLocation(view, Gravity.CENTER, 0, 0);
startRecording();
break;default:
break;
}
return false;
}红色部分为报错地方,求大神给分析一下原因

解决方案 »

  1.   

    关键代码如下:
    View functionsView = LayoutInflater.from(context).inflate(R.layout.popup_dianming_btn, null);functionsView.findViewById(R.id.voiceLL).setOnTouchListener(new       
    SoundOnTouchUtilListener(context,data.get(groupPosition), functionsView.findViewById(R.id.voiceLL)));SoundOnTouchUtilListener如下public SoundOnTouchUtilListener(Context context,List<Visitor> listCard,View view){
    this.listCard=listCard;
    this.context=context;
    this.view=view;
    if(recordingSoundWin==null){
    recordingSoundWin=new PopupWindow(LayoutInflater.from(context)
    .inflate(R.layout.popupwindow_recordsound, null),
    LayoutParams.MATCH_PARENT,
    LayoutParams.MATCH_PARENT);
    ImageView rocketImage = (ImageView)recordingSoundWin.getContentView().findViewById(R.id.rocketImage); 
    rocketImage.setBackgroundResource(R.anim.imgchange); 
    rocketAnimation=(AnimationDrawable)rocketImage.getBackground();
    }
    clockLL=(LinearLayout)recordingSoundWin.getContentView().findViewById(R.id.clockLL);
    clockTextView=(TextView)recordingSoundWin.getContentView().findViewById(R.id.clockTextView);
    }
    public boolean onTouch(View v, MotionEvent event) {
    //ACTION_MOVE=2, ACTION_UP = 1,ACTION_DOWN = 0;
    if(listCard==null||listCard.size()==0){
    Toast.makeText(context, R.string.nocards, Toast.LENGTH_SHORT).show();
    return false;
    }
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    recordingSoundWin.showAtLocation(view, Gravity.CENTER, 0, 0);
    startRecording();
    break;default:
    break;
    }
    return false;
    }红色部分为报错地方,求大神给分析一下原因
    没有看到红色
      

  2.   

    关键代码如下:
    View functionsView = LayoutInflater.from(context).inflate(R.layout.popup_dianming_btn, null);functionsView.findViewById(R.id.voiceLL).setOnTouchListener(new       
    SoundOnTouchUtilListener(context,data.get(groupPosition), functionsView.findViewById(R.id.voiceLL)));SoundOnTouchUtilListener如下public SoundOnTouchUtilListener(Context context,List<Visitor> listCard,View view){
    this.listCard=listCard;
    this.context=context;
    this.view=view;
    if(recordingSoundWin==null){
    recordingSoundWin=new PopupWindow(LayoutInflater.from(context)
    .inflate(R.layout.popupwindow_recordsound, null),
    LayoutParams.MATCH_PARENT,
    LayoutParams.MATCH_PARENT);
    ImageView rocketImage = (ImageView)recordingSoundWin.getContentView().findViewById(R.id.rocketImage); 
    rocketImage.setBackgroundResource(R.anim.imgchange); 
    rocketAnimation=(AnimationDrawable)rocketImage.getBackground();
    }
    clockLL=(LinearLayout)recordingSoundWin.getContentView().findViewById(R.id.clockLL);
    clockTextView=(TextView)recordingSoundWin.getContentView().findViewById(R.id.clockTextView);
    }
    public boolean onTouch(View v, MotionEvent event) {
    //ACTION_MOVE=2, ACTION_UP = 1,ACTION_DOWN = 0;
    if(listCard==null||listCard.size()==0){
    Toast.makeText(context, R.string.nocards, Toast.LENGTH_SHORT).show();
    return false;
    }
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    recordingSoundWin.showAtLocation(view, Gravity.CENTER, 0, 0);
    startRecording();
    break;default:
    break;
    }
    return false;
    }红色部分为报错地方,求大神给分析一下原因
    没有看到红色
    recordingSoundWin.showAtLocation(view, Gravity.CENTER, 0, 0); 这句出错,我感觉是View 的问题
      

  3.   

    你看下新定义一个view=functionsView。findviewbydId,看看出错不
      

  4.   

    我怀疑你这里的context是不是指父类的popwindow而不是指activity,传进来的context改成 XXacitvity.this.getParent()试试
      

  5.   


    private DianmingActivity activity;

    public SoundOnTouchDianmingListener(Context context,List<Visitor> listCard,View view){
    this.listCard=listCard;
    this.context=context;
    this.view=view;
    activity=(DianmingActivity)context;
    if(recordingSoundWin==null){
    recordingSoundWin=new PopupWindow(LayoutInflater.from(activity.getParent())
    .inflate(R.layout.popupwindow_recordsound, null),
    LayoutParams.MATCH_PARENT,
    LayoutParams.MATCH_PARENT);
    ImageView rocketImage = (ImageView)recordingSoundWin.getContentView().findViewById(R.id.rocketImage); 
    rocketImage.setBackgroundResource(R.anim.imgchange); 
    rocketAnimation=(AnimationDrawable)rocketImage.getBackground();
    }
    clockLL=(LinearLayout)recordingSoundWin.getContentView().findViewById(R.id.clockLL);
    clockTextView=(TextView)recordingSoundWin.getContentView().findViewById(R.id.clockTextView);
    }
      

  6.   


    按照您说的我修改代码如上,但是还是出现问题。好吧,那我就没发解决了popupWindow 弹出另一个PopupWindow这功能是否能实现?您那还有别的方式实现这种效果吗?