自定义对话框隐藏在另一个活动

时间:2018-03-29 13:17:41

标签: android android-layout android-activity

我是android新手。目前正在使用Caller Id应用,例如' truecaller'。我正在显示呼叫日志屏幕并单击呼叫日志条目(这是linearlayout)我正在调用Action_Call intent。

private View setList(int position, ViewGroup parent) {
        LayoutInflater inf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        final View row = inf.inflate(R.layout.liststyle, parent, false);

        TextView tvName = (TextView) row.findViewById(R.id.tvNameMain);
        final TextView tvNumber = (TextView) row.findViewById(R.id.tvNumberMain);
        TextView tvTime = (TextView) row.findViewById(R.id.tvTime);
        TextView tvDate = (TextView) row.findViewById(R.id.tvDate);
        //TextView tvType = (TextView) row.findViewById(R.id.tvType);
        ImageView tvImageView = (ImageView) row.findViewById(R.id.tvTypeImage);

        final LinearLayout callLogLayout = (LinearLayout) row.findViewById(R.id.callLogLayout);
        callLogLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final int REQUEST_PHONE_CALL = 1;
                String Number = tvNumber.getText().toString();
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                if ( ContextCompat.checkSelfPermission( row.getContext(), Manifest.permission.CALL_PHONE ) != PackageManager.PERMISSION_GRANTED ) {

                    ActivityCompat.requestPermissions( CallLogActivity.this, new String[] {  android.Manifest.permission.CALL_PHONE  },
                            REQUEST_PHONE_CALL );
                }
                callIntent.setData(Uri.parse("tel:" + Number));
                startActivity(callIntent);
            }
        });

屏幕如下所示。

enter image description here

我的问题是'自定义来电显示对话框'我在拨出电话开始时显示的内容会粘在屏幕上方(通话记录屏幕)并且不会在实际通话屏幕上显示。

当我点击屏幕下方的“呼叫记录”条目时会弹出。

enter image description here

当我点击结束通话按钮时,我可以看到自定义对话框。

enter image description here

OnCallStateChanged

case TelephonyManager.CALL_STATE_OFFHOOK:
            //Transition of ringing->offhook are pickups of incoming calls.  Nothing done on them
            if (lastState != TelephonyManager.CALL_STATE_RINGING) {
                isIncoming = false;
                callStartTime = new Date();
                contactName = CallSmsDetector.retrieveContactName(context, savedNumber);
                // CallSmsDetector.startRecording(context);
                mCallListener.onOutgoingCallStarted(context, savedNumber, callStartTime, contactName);
                //mCallListener.onOutgoingCallEnded(context,savedNumber,callStartTime,contactName);
            } else {
                isIncoming = true;
                callStartTime = new Date();
                contactName = CallSmsDetector.retrieveContactName(context, savedNumber);
                // CallSmsDetector.startRecording(context);
                // mCallListener.onIncomingCallAnswered(context, savedNumber, callStartTime, contactName);
                //mCallListener.onIncomingCallEnded(context,savedNumber,callStartTime,contactName);
            }
            break;

OnOutgoingCallStarted

public void onOutgoingCallStarted(Context ctx, String number, Date start, String contactName)
        {
            //popup(contactName, number);
            cName = contactName;
            Log.e("onOutgoingCallStarted","onOutgoingCallStarted");
            if(contactName==""){
                Intent i=new Intent(ctx,PopupActivity.class);
                i.putExtra("DATAPASSED",number);
                Log.e("number",number);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);

            }
            else
            {
                Log.e("Contact number",contactName);
                Intent i=new Intent(ctx,PopupActivity.class);
                i.putExtra("DATAPASSED",contactName);
                i.putExtra("Number",number);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);

            }

            Log.e("outgoing call started", number);

        }

是否需要延迟?我没有得到任何线索。

UPDATE 每当我在代码中放置断点时,令人惊讶的是它完美无缺。

我甚至试图延迟但没有运气。

enter image description here

1 个答案:

答案 0 :(得分:0)

在我看来,你有一个上下文问题。我多次遇到这个问题,我通过了getActivity(),弹出菜单出现在我的活动后面。我想如果你将setList()中的第一行改为

LayoutInflater inflater = LayoutInflater.from(parent.getContext());

应该可以正常工作。 试着让我知道。