android手机源码联系人页面添加紧急电话模块

根据读源码可知,所有显示联系人页面是在DefaultContactBrowseListFragment类,在其类中我们可一发现 private void addEmptyUserProfileHeader(LayoutInflater inflater)这样一个方法,其方法的作用就是动态的添加ListView(显示联系人)以上的控件,所以我们想要在联系人以上添加模块就要了解,其方法里动态添加模块的流程,
     方法的里
 ListView list = getListView();
        // Put a header with the "ME" name and a view for the number of contacts
        // The view is embedded in a frame view since you cannot change the visibility of a
        // view in a ListView without having a parent view.
        mProfileHeaderContainer = new FrameLayout(inflater.getContext());
        mProfileHeaderContainerCall = new FrameLayout(inflater.getContext());
        mProfileHeader = inflater.inflate(R.layout.user_profile_header, null, false);
        mProfileHeaderCall = inflater.inflate(R.layout.user_profile_header_call, null, false);
        mCounterHeaderView = (TextView) mProfileHeader.findViewById(R.id.contacts_count);
        mProfileTitle = (TextView) mProfileHeader.findViewById(R.id.profile_title);
        mProfileHeaderContainer.addView(mProfileHeader);
        mProfileHeaderContainerCall.addView(mProfileHeaderCall);
        list.addHeaderView(mProfileHeaderContainer, null, false);

是添加头控件的标题所以我们可以在这个地方添加我们自己想要的模块
mMessageContainer = new FrameLayout(inflater.getContext());
        mMessageContainerCall = new FrameLayout(inflater.getContext());
        mMessageContainerFire = new FrameLayout(inflater.getContext());
        mProfileMessage = (Button)inflater.inflate(R.layout.user_profile_button, null, false);
        mProfileMessageCall = (Button)inflater.inflate(R.layout.user_profile_button_call, null, false);
        mProfileMessageFire = (Button)inflater.inflate(R.layout.user_profile_button_fire, null, false);
        mMessageContainer.addView(mProfileMessage);
        mMessageContainerCall.addView(mProfileMessageCall);
        mMessageContainerFire.addView(mProfileMessageFire);
        list.addHeaderView(mMessageContainer, null, true);
        list.addHeaderView(mProfileHeaderContainerCall, null, false);
        list.addHeaderView(mMessageContainerCall, null, true);
        list.addHeaderView(mMessageContainerFire, null, true);

        mProfileMessage.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
                intent.putExtra(ContactEditorFragment.INTENT_EXTRA_NEW_LOCAL_PROFILE, true);
                startActivity(intent);
            }
        });
        mProfileMessageCall.setOnClickListener(new View.OnClickListener(){
            public void onClick(View arg0) {
                Uri uri = Uri.parse("tel:110");
                Intent intent = new Intent(Intent.ACTION_DIAL,uri);
                  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  startActivity(intent);
            }
        });
再有就是可以添加其他的控件还有事件监听,来完成自己的需求。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值