Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

In this page you can find the example usage for android.widget ImageView setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:musicplayer.MusicActivity.java

/**
 * Called when the activity is first created. Here, we simply set the event listeners and
 * start the background service ({@link MusicService}) that will handle the actual media
 * playback./*from w ww  . j  av a 2  s.com*/
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.music_view);

    mPlayButton = (ImageButton) findViewById(R.id.playbutton);
    mPauseButton = (ImageButton) findViewById(R.id.pausebutton);
    mSkipButton = (ImageButton) findViewById(R.id.skipbutton);
    mRewindButton = (ImageButton) findViewById(R.id.rewindbutton);
    //        mStopButton = (Button) findViewById(R.id.stopbutton);
    //        mEjectButton = (Button) findViewById(R.id.ejectbutton);
    mSeekBar = (SeekBar) findViewById(R.id.SeekBar);
    mSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);
    mTitleText = (TextView) findViewById(R.id.songTitleText);
    mTimeText = (TextView) findViewById(R.id.timeText);

    mPlayButton.setOnClickListener(this);
    mPauseButton.setOnClickListener(this);
    mSkipButton.setOnClickListener(this);
    mRewindButton.setOnClickListener(this);
    //        mStopButton.setOnClickListener(this);
    //        mEjectButton.setOnClickListener(this);

    //Start service with initilise, else if bind service was the thing that started
    //then the service will kill itself once unBound
    startService(new Intent(MusicService.ACTION_INITIALISE));

    mViewPager = (ViewPager) findViewById(R.id.viewpager);
    mTabs = (SwipeyTabs) findViewById(R.id.swipeytabs);

    adapter = new SwipeyTabsPagerAdapter(this, getSupportFragmentManager());
    mViewPager.setAdapter(adapter);
    mTabs.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(mTabs);
    mViewPager.setCurrentItem(0);

    try {
        book = getIntent().getExtras().getString("Book");
        chapter = getIntent().getExtras().getInt("Chapter");
        translation = getIntent().getExtras().getString("Translation");
    } catch (NullPointerException e) {
        //Default to John if it isn't called from within the passage
        book = "John";
        chapter = 1;
        translation = "ESV";
    }

    ImageView up = (ImageView) findViewById(R.id.title_bar_icon);
    up.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Intent i = new Intent(MusicActivity.this, MainActivity.class);
            startActivity(i);
        }

    });

}

From source file:com.ccxt.whl.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);/*  w  w w  .  ja  v  a 2s.  co  m*/
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();
    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList, sidebar);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = DemoApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else if (Constant.KEFU.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", Constant.KEFU)
                        .putExtra("chatType", 0));

            } else {
                //Intent intent = new Intent(getActivity(), Userinfo.class);
                //intent.putExtra("userId", mAdapter.getItem(position-1).getUsername());
                // demo??
                startActivity(new Intent(getActivity(), Userinfo.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

}

From source file:com.safeness.im.activity.ContactlistFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    //T??home???appcrash
    if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false))
        return;/*w  ww  . j a  va 2  s.co m*/
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) getView().findViewById(R.id.list);
    sidebar = (Sidebar) getView().findViewById(R.id.sidebar);
    sidebar.setListView(listView);
    //???
    blackList = EMContactManager.getInstance().getBlackListUsernames();
    contactList = new ArrayList<User>();
    // ?contactlist
    getContactList();
    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList, sidebar);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = PatientApplication.getInstance().getContactList()
                        .get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId",
                        adapter.getItem(position).getUsername()));
            }
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), AddContactActivity.class));
        }
    });
    registerForContextMenu(listView);

}

From source file:com.money.manager.ex.about.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    String text, version;//from w  ww.j  av  a 2s  .c o m
    View view = inflater.inflate(R.layout.about_fragment, container, false);

    MmxBaseFragmentActivity activity = (MmxBaseFragmentActivity) getActivity();
    if (activity != null && activity.getSupportActionBar() != null) {
        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    // Version application
    TextView txtVersion = (TextView) view.findViewById(R.id.textViewVersion);
    Core core = new Core(getActivity());
    version = core.getAppVersionName();
    //        build = core.getAppVersionBuild();
    txtVersion.setText(getString(R.string.version) + " " + version);
    // + " (" + getString(R.string.build) + " " + build + ")"

    // Send Feedback
    TextView txtFeedback = (TextView) view.findViewById(R.id.textViewLinkFeedback);
    text = "<u>" + txtFeedback.getText() + "</u>";
    txtFeedback.setText(Html.fromHtml(text));
    txtFeedback.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("message/rfc822");
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.EMAIL });
            intent.putExtra(Intent.EXTRA_SUBJECT, "MoneyManagerEx for Android: Feedback");
            try {
                startActivity(Intent.createChooser(intent, "Send mail..."));
            } catch (Exception e) {
                Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    });

    // rate application
    TextView txtRate = (TextView) view.findViewById(R.id.textViewLinkRate);
    text = "<u>" + txtRate.getText() + "</u>";
    txtRate.setText(Html.fromHtml(text));
    txtRate.setMovementMethod(LinkMovementMethod.getInstance());
    OnClickListenerUrl clickListenerRate = new OnClickListenerUrl();
    clickListenerRate.setUrl("http://play.google.com/store/apps/details?id=com.money.manager.ex");
    txtRate.setOnClickListener(clickListenerRate);

    // application issue tracker
    TextView txtIssues = (TextView) view.findViewById(R.id.textViewIssuesTracker);
    text = "<u>" + txtIssues.getText() + "</u>";
    txtIssues.setText(Html.fromHtml(text));
    txtIssues.setMovementMethod(LinkMovementMethod.getInstance());
    OnClickListenerUrl clickListenerIssuesTracker = new OnClickListenerUrl();
    clickListenerIssuesTracker.setUrl("https://github.com/moneymanagerex/android-money-manager-ex/issues/");
    txtIssues.setOnClickListener(clickListenerIssuesTracker);

    // MMEX for Android web page
    TextView txtWebsite = (TextView) view.findViewById(R.id.textViewWebSite);
    text = "<u>" + txtWebsite.getText() + "</u>";
    txtWebsite.setText(Html.fromHtml(text));
    txtWebsite.setMovementMethod(LinkMovementMethod.getInstance());
    OnClickListenerUrl clickListenerWebsite = new OnClickListenerUrl();
    clickListenerWebsite.setUrl("http://android.moneymanagerex.org/");
    txtWebsite.setOnClickListener(clickListenerWebsite);

    // report set link
    TextView txtReport = (TextView) view.findViewById(R.id.textViewLinkWebSite);
    text = "<u>" + txtReport.getText() + "</u>";
    txtReport.setText(Html.fromHtml(text));
    txtReport.setMovementMethod(LinkMovementMethod.getInstance());
    OnClickListenerUrl clickListenerFeedback = new OnClickListenerUrl();
    clickListenerFeedback
            .setUrl("http://www.moneymanagerex.org/?utm_campaign=Application_Android&utm_medium=MMEX_" + version
                    + "&utm_source=Website");
    txtReport.setOnClickListener(clickListenerFeedback);

    // image view google plus
    OnClickListenerUrl clickListenerGooglePlus = new OnClickListenerUrl();
    clickListenerGooglePlus.setUrl("http://goo.gl/R693Ih");
    ImageView imageViewGooglePlus = (ImageView) view.findViewById(R.id.imageViewGooglePlus);
    imageViewGooglePlus.setOnClickListener(clickListenerGooglePlus);

    // image view github
    OnClickListenerUrl clickListenerGithub = new OnClickListenerUrl();
    clickListenerGithub.setUrl("https://github.com/moneymanagerex/android-money-manager-ex");
    ImageView imageViewGithub = (ImageView) view.findViewById(R.id.imageViewGithub);
    imageViewGithub.setOnClickListener(clickListenerGithub);
    // image view twitter
    OnClickListenerUrl clickListenerTwitter = new OnClickListenerUrl();
    clickListenerTwitter.setUrl("https://twitter.com/MMEX4Android");
    ImageView imageViewTwitter = (ImageView) view.findViewById(R.id.imageViewTwitter);
    imageViewTwitter.setOnClickListener(clickListenerTwitter);
    // GPLv2 license
    TextView txtLicense = (TextView) view.findViewById(R.id.textViewLicense);
    text = "<u>" + txtLicense.getText() + "</u>";
    txtLicense.setText(Html.fromHtml(text));
    OnClickListenerUrl clickListenerLicense = new OnClickListenerUrl();
    clickListenerLicense.setUrl("http://www.gnu.org/licenses/old-licenses/gpl-2.0.html");
    txtLicense.setOnClickListener(clickListenerLicense);
    // logcat
    TextView txtLogcat = (TextView) view.findViewById(R.id.textViewLogcat);
    text = "<u>" + txtLogcat.getText() + "</u>";
    txtLogcat.setText(Html.fromHtml(text));
    txtLogcat.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            LynxConfig lynxConfig = new LynxConfig();
            lynxConfig.setMaxNumberOfTracesToShow(4000);

            Intent lynxActivityIntent = LynxActivity.getIntent(getActivity(), lynxConfig);
            startActivity(lynxActivityIntent);
        }
    });

    // Donate, button
    Button buttonDonate = (Button) view.findViewById(R.id.buttonDonateInApp);
    buttonDonate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), DonateActivity.class));
        }
    });

    // Send logcat button
    Button sendLogcatButton = (Button) view.findViewById(R.id.sendLogcatButton);
    sendLogcatButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sendLogcat();
        }
    });
    return view;
}

From source file:com.posagent.fragments.RegisterFragment.java

private void initViews(View view) {
    if (userKind == Constants.UserConstant.USER_KIND_PESONAL) {
        View company1 = view.findViewById(R.id.company_content1);
        company1.setVisibility(View.GONE);
        View company2 = view.findViewById(R.id.company_content2);
        company2.setVisibility(View.GONE);
    }/*from  www .jav  a 2  s . co  m*/

    view.findViewById(R.id.mi_select_city).setOnClickListener(this);

    view.findViewById(R.id.btn_submit).setOnClickListener(this);

    tvCityName = (TextView) view.findViewById(R.id.tv_city_name);

    //photo
    TextView tv_card_photo = (TextView) view.findViewById(R.id.tv_card_photo);
    tv_card_photo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentKind = "card";
            photoManager.prompt();
        }
    });

    TextView tv_license_photo = (TextView) view.findViewById(R.id.tv_license_photo);
    tv_license_photo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentKind = "license";
            photoManager.prompt();
        }
    });
    TextView tv_tax_photo = (TextView) view.findViewById(R.id.tv_tax_photo);
    tv_tax_photo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentKind = "tax";
            photoManager.prompt();
        }
    });

    ImageView iv_card_photo = (ImageView) view.findViewById(R.id.iv_card_photo);
    iv_card_photo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentKind = "card";
            Intent i = new Intent(getActivity(), ImageViewer.class);
            i.putExtra("url", cardIdPhotoPath);
            startActivityForResult(i, Constants.REQUEST_CODE);
        }
    });

    ImageView iv_license_photo = (ImageView) view.findViewById(R.id.iv_license_photo);
    iv_license_photo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentKind = "license";
            Intent i = new Intent(getActivity(), ImageViewer.class);
            i.putExtra("url", licenseNoPicPath);
            startActivityForResult(i, Constants.REQUEST_CODE);
        }
    });

    ImageView iv_tax_photo = (ImageView) view.findViewById(R.id.iv_tax_photo);
    iv_tax_photo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentKind = "tax";
            Intent i = new Intent(getActivity(), ImageViewer.class);
            i.putExtra("url", taxNoPicPath);
            startActivityForResult(i, Constants.REQUEST_CODE);
        }
    });

}

From source file:com.pertamina.tbbm.rewulu.ecodriving.ContentsActivity.java

private void initPanel() {
    // TODO Auto-generated method stub
    imgs = new ArrayList<>();
    panel.removeAllViews();/*from   w  w  w.  ja  va2s. c  o  m*/
    for (int w = 0; w < pageSize; w++) {
        ImageView img = new ImageView(getApplicationContext());
        img.setLayoutParams(params);
        if (0 == w)
            img.setImageResource(R.drawable.panel_indicator_full);
        else
            img.setImageResource(R.drawable.panel_indicator);
        img.setVisibility(View.VISIBLE);
        img.setOnClickListener(this);
        panel.addView(img);
        imgs.add(img);
    }

}

From source file:com.telestax.mayday_customer.fragment.CustomerSupportFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View viewInfo = inflater.inflate(R.layout.customer_support, container, false);

    // Initialize UI
    mImageViewCustomerMayDayCall = (ImageView) viewInfo.findViewById(R.id.imageView_customer_two_mayday);
    ImageView imageViewCustomerSupportBack = (ImageView) viewInfo
            .findViewById(R.id.imageView_customer_support_back);

    TextView textViewSupport = (TextView) viewInfo.findViewById(R.id.customer_support);
    textViewSupport.setOnClickListener(this);
    mImageViewCustomerMayDayCall.setOnClickListener(this);
    imageViewCustomerSupportBack.setOnClickListener(this);

    String mayDayAction = MainActivity.getMaydaySharePref(getActivity());
    if (mayDayAction != null) {
        if (mayDayAction.equalsIgnoreCase(Constant.YES)) {
            mImageViewCustomerMayDayCall.setVisibility(View.INVISIBLE);
        } else {//w  ww. j  av  a  2  s .c om
            mImageViewCustomerMayDayCall.setVisibility(View.VISIBLE);
        }
    }

    mInitReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            mImageViewCustomerMayDayCall.setVisibility(View.VISIBLE);
        }
    };

    //Register broadcast receiver
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mInitReceiver,
            new IntentFilter(Constant.BROADCAST_INTENT));
    return viewInfo;
}

From source file:com.mk27manoj.crewtools.fragments.CreateViewCompanyFragment.java

private void addService(String name) {
    LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View baseView = layoutInflater.inflate(R.layout.row_create_company_add_service, null);
    TextView txtService = (TextView) baseView.findViewById(R.id.textview_create_company_add_service_name);
    ImageView imgRemove = (ImageView) baseView.findViewById(R.id.imageview_create_company_add_service_remove);
    baseView.setTag(serviceContainer.getChildCount());
    imgRemove.setTag(serviceContainer.getChildCount());

    txtService.setText(name);//from w  w  w .j  a  va 2s  .  com
    imgRemove.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((LinearLayout) baseView.getParent()).removeView(baseView);
            services.remove(serviceContainer.indexOfChild(v));
            mCompany.setServiceTypes(services);
        }
    });
    serviceContainer.addView(baseView);
}

From source file:com.golden.android.eyecare.ForegroundService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    ///* ww  w  . j  a  v a  2s .c o m*/
    //Do nothing If you already exist Manager
    if (mFloatingViewManager != null) {
        return START_REDELIVER_INTENT;
    }
    final DisplayMetrics metrics = new DisplayMetrics();
    final WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);
    final LayoutInflater inflater = LayoutInflater.from(this);
    //        Vibrator v = (Vibrator) this.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    //        // Vibrate for 500 milliseconds
    //        v.vibrate(1000);
    //        if(intent.getExtras()==null)
    //        {
    //
    //        }
    //        else {
    //            Boolean data = (Boolean) intent.getExtras().getBoolean("noticlick");
    //
    //            if (data) {
    //
    //                launchCount();
    //                //Do your stuff here mate :)
    //            }
    //        }

    final ImageView iconView = (ImageView) inflater.inflate(R.layout.floating, null, false);
    iconView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // ?
            //                final Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", getString(R.string.mail_address), null));
            //                intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.mail_title));
            //                intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.mail_content));
            //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //                startActivity(intent);
            launchCount();

        }
    });

    //        String ToastString = getString(R.string.Toasttext1) + " " + checkTime() + " " + getString(R.string.Toasttext2);
    //        Toast toast = Toast.makeText(getApplicationContext(), ToastString, Toast.LENGTH_SHORT);
    ////      Set the Gravity to Top and Left
    //        toast.setGravity(Gravity.TOP | Gravity.LEFT, 100, 200);
    //        toast.setDuration(Toast.LENGTH_LONG);
    //
    //        ViewGroup group = (ViewGroup) toast.getView();
    //        TextView messageTextView = (TextView) group.getChildAt(0);
    //        messageTextView.setTextSize(20);
    //        toast.show();

    mFloatingViewManager = new FloatingViewManager(this, this);
    mFloatingViewManager.setFixedTrashIconImage(R.drawable.ic_trash_fixed);
    mFloatingViewManager.setActionTrashIconImage(R.drawable.ic_trash_action);
    // Setting Options(you can change options at any time)
    loadDynamicOptions();
    // Initial Setting Options (you can't change options after created.)
    final FloatingViewManager.Options options = loadOptions(metrics);
    mFloatingViewManager.addViewToWindow(iconView, options);
    mFloatingViewManager.setDisplayMode(FloatingViewManager.DISPLAY_MODE_SHOW_ALWAYS);

    notify(intent);

    return START_REDELIVER_INTENT;
}

From source file:itstudio.instructor.fragment.ContactlistFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_contact_list, container, false);
    inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) view.findViewById(R.id.list);
    sidebar = (Sidebar) view.findViewById(R.id.sidebar);
    sidebar.setListView(listView);/*w ww . j  ava  2s  .  c o m*/
    // ???
    contactList = new ArrayList<User>();
    // ?contactlist
    if (DemoHXSDKHelper.getInstance().isLogined()) {
        blackList = EMContactManager.getInstance().getBlackListUsernames();
        getContactList();
    }
    // adapter
    adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList, sidebar);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String username = adapter.getItem(position).getUsername();
            if (Constant.NEW_FRIENDS_USERNAME.equals(username)) {
                // ?
                User user = MyApplication.getInstance().getContactList().get(Constant.NEW_FRIENDS_USERNAME);
                user.setUnreadMsgCount(0);
                startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class));
            } else if (Constant.GROUP_USERNAME.equals(username)) {
                // ??
                startActivity(new Intent(getActivity(), GroupsActivity.class));
            } else {
                // demo??
                startActivity(new Intent(getActivity(), ChatActivity.class)
                        .putExtra("userId", adapter.getItem(position).getUsername())
                        .putExtra("name", adapter.getItem(position).getName()));
            }
            // ??
        }
    });
    listView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ??
            if (getActivity().getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getActivity().getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    ImageView addContactView = (ImageView) view.findViewById(R.id.iv_new_contact);
    // ?
    addContactView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (DemoHXSDKHelper.getInstance().isLogined()) {

                startActivity(new Intent(getActivity(), AddContactActivity.class));
            } else {
                Toast.makeText(getActivity(), "?", 0).show();
            }
        }
    });
    registerForContextMenu(listView);
    return view;
}