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:com.lnpdit.chatuidemo.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 = CydlApplication.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.cleanwiz.applock.ui.activity.SplashActivity.java

public void showUpdateDialog(String intro) {
    final AlertDialog updateDialogDlg = new AlertDialog.Builder(this).create();
    updateDialogDlg.show();//from   w  w  w.j  a  va  2 s . c om
    Window win = updateDialogDlg.getWindow();
    win.setContentView(R.layout.dialog_update);
    TextView tvMsg = (TextView) win.findViewById(R.id.tvMsg);
    tvMsg.setText(intro);
    Button btOk = (Button) win.findViewById(R.id.btOk);
    ImageView closeImageView = (ImageView) win.findViewById(R.id.updateclose);
    closeImageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            updateDialogDlg.dismiss();
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_CANCEL;
            handler.sendMessage(msg);
        }
    });

    btOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_DOWN;
            handler.sendMessage(msg);
        }
    });

    updateDialogDlg.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            List<UpdateVersionManafer> updateVersionManafers = updateVersionManagerService.getVersionManafers();
            for (UpdateVersionManafer updateVersionManafer : updateVersionManafers) {
                updateVersionManafer.setLasttipdate(new Date().getTime());
                updateVersionManagerService.modifyTipsDate(updateVersionManafer);
                break;
            }
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_CANCEL;
            handler.sendMessage(msg);
        }
    });
}

From source file:com.starwood.anglerslong.LicenseActivity.java

/******************************************************************************************************************************************
 * Populates all of the tabs that have been added to this feature.
 * Sets an onClickListener to each one of the items
 * Keeps track of all the button ID's/*ww  w  . j  av  a  2s .  co  m*/
 * Keeps track of the TOTAL number of items in the list.
 * *****************************************************************************************************************************************
 * @param json
 * @throws JSONException
 ******************************************************************************************************************************************/
private void populateLicense(String json, boolean isRestart) throws JSONException {

    //**** Used to get the correct relative layout ****//
    int[] rlIdArray = { R.id.rl1, R.id.rl2, R.id.rl3, R.id.rl4, R.id.rl5 };
    //**** Get the correct textview and populate it ****//
    int[][] textViewIdArray = { { R.id.name_rl, R.id.name_rl2, R.id.name_rl3, R.id.name_rl4, R.id.name_rl5 },
            { R.id.number_rl, R.id.number_rl2, R.id.number_rl3, R.id.number_rl4, R.id.number_rl5 },
            { R.id.type_rl, R.id.type_rl2, R.id.type_rl3, R.id.type_rl4, R.id.type_rl5 },
            { R.id.issuedate_rl, R.id.issuedate_rl2, R.id.issuedate_rl3, R.id.issuedate_rl4,
                    R.id.issuedate_rl5 },
            { R.id.expdate_rl, R.id.expdate_rl2, R.id.expdate_rl3, R.id.expdate_rl4, R.id.expdate_rl5 },
            { R.id.birthday_rl, R.id.birthday_rl2, R.id.birthday_rl3, R.id.birthday_rl4, R.id.birthday_rl5 },
            { R.id.huntered_rl, R.id.huntered_rl2, R.id.huntered_rl3, R.id.huntered_rl4, R.id.huntered_rl5 },
            { R.id.flag_rl, R.id.flag_rl2, R.id.flag_rl3, R.id.flag_rl4, R.id.flag_rl5 } };
    //**** Populate the state flag the user chose ****//
    int[] flagArray = { R.drawable.sc_flag, R.drawable.ga_flag, R.drawable.fl_flag, R.drawable.al_flag,
            R.drawable.ms_flag };
    //**** These are oll the options the user can enter ****//
    String[] jsonStrings = { "name", "number", "type", "issue_date", "exp_date", "birthday", "huntered",
            "state" };
    numItems = 0;
    JSONObject j = new JSONObject(json); // Whole JSON String
    JSONObject outer = j.getJSONObject("outermost"); // Outermost JSON
    JSONArray licenseArray = outer.getJSONArray("license");
    if (licenseArray.length() == 0 || licenseArray == null) {
        isLicensePopulated = true;
        isArrayEmpty = true;
    }

    for (int i = 0; i < licenseArray.length(); i++) {
        if (isRestart && !isEdit)
            i = licenseArray.length() - 1; // Execute this only if you just added a button (so you dont reload all buttons).
        else if (isEdit) {
            isEdit = false;
            break;
        }

        findViewById(rlIdArray[i]).setVisibility(View.VISIBLE);

        JSONObject temp = licenseArray.getJSONObject(i);

        TextView tv;
        for (int n = 0; n < jsonStrings.length; n++) {
            if (n == 7) { // Only go here if you're populating the FLAG (b/c it's not a textview)
                ImageView flag = (ImageView) findViewById(textViewIdArray[n][i]);
                flag.setImageDrawable(getResources()
                        .getDrawable(flagArray[Integer.parseInt(temp.getString(jsonStrings[n]))]));
                continue;
            }
            tv = (TextView) findViewById(textViewIdArray[n][i]);
            tv.setText(temp.getString(jsonStrings[n]));
        }

        ImageView licenseImage = (ImageView) findViewById(imageViewIdArray[i]);
        licenseImage.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                clickedItem(v);
            }
        });

        isArrayEmpty = false;
        isLicensePopulated = true;
        numItems++; // <<<<------- Lets you know how many items are populated on screen
    }
}

From source file:com.casin.activity.HomeDrawerActivity.java

public void initHeaderLayout(String name, String balancePoints) {
    Typeface snapFont = Typeface.createFromAsset(getAssets(), "SNAP.TTF");
    TextView headrTitleTextView = (TextView) findViewById(R.id.headerTitle);
    headrTitleTextView.setTypeface(snapFont);
    headrTitleTextView.setText(name);/*from w  ww  .  j a  v  a  2  s  .  c  om*/

    TextView scoreTitleTextView = (TextView) findViewById(R.id.score);
    scoreTitleTextView.setText(balancePoints);

    ImageView leftMenuBarImageView = (ImageView) findViewById(R.id.leftMenuBar);
    leftMenuBarImageView.setVisibility(View.VISIBLE);
    leftMenuBarImageView.setOnClickListener(leftMenuBarClickListener);
}

From source file:niltor.net.chatuidemo.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);/*from  w w w.  j  a v a  2  s.com*/
    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 {
                // 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.ouyangzn.github.module.main.MainActivity.java

@Override
protected void initView(Bundle savedInstanceState) {
    Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
    UiUtils.setCenterTitle(toolbar, R.string.app_name);
    ImageView collectImg = UiUtils.addImage2Toolbar(toolbar, R.drawable.selector_collect, Gravity.END,
            new int[] { 0, 0, ScreenUtils.dp2px(mContext, 15), 0 });
    collectImg.setId(R.id.id_toolbar_right_img);
    collectImg.setOnClickListener(this);
    // @BindView ?NavigationViewviewfind?
    mNavView = ButterKnife.findById(this, R.id.nav_view);
    mNavView.setNavigationItemSelectedListener(this);
    View headerView = mNavView.getHeaderView(0);
    mImgAvatar = (ImageView) headerView.findViewById(R.id.img_photo);
    mTvEmail = (TextView) headerView.findViewById(R.id.tv_email);
    User user = App.getUser();//from   w w w  .j  a  v a  2  s  . c  o  m
    if (user != null) {
        ImageLoader.loadAsCircle(mImgAvatar, R.drawable.ic_default_photo, user.getAvatarUrl());
        mTvEmail.setText(user.getEmail());
    } else {
        mImgAvatar.setImageResource(R.drawable.ic_default_photo);
        mTvEmail.setText(null);
    }

    // @BindView ?
    mDrawerLayout = ButterKnife.findById(this, R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawerLayout.addDrawerListener(toggle);
    toggle.syncState();

    ViewPager viewPager = ButterKnife.findById(this, R.id.view_pager_main);
    TabLayout tabLayout = ButterKnife.findById(this, R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    /** ?list **/
    List<Fragment> fragmentList = new ArrayList<>();
    /** ?title list **/
    String[] array = getResources().getStringArray(R.array.array_language);
    List<String> titleList = Arrays.asList(array);
    for (String title : titleList) {
        fragmentList.add(MainFragment.getInstance(title));
    }
    viewPager.setAdapter(new MainPagerAdapter(getSupportFragmentManager(), fragmentList, titleList));
    viewPager.setOffscreenPageLimit(fragmentList.size());
}

From source file:com.coinblesk.client.CurrentBalanceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_balance, container, false);

    recyclerView = (RecyclerView) view.findViewById(R.id.txhistoryview);
    View empty = view.findViewById(R.id.txhistory_emptyview);
    recyclerView.setEmptyView(empty);/*from   w  w  w .jav a 2s  . c o m*/
    transactionAdapter = new TransactionWrapperRecyclerViewAdapter(new ArrayList<TransactionWrapper>());
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    recyclerView.setAdapter(transactionAdapter);
    updateTransactions();

    ImageView switcher = (ImageView) view.findViewById(R.id.balance_switch_image_view);
    switcher.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (SharedPrefUtils.isBitcoinPrimaryBalance(getActivity())) {
                SharedPrefUtils.setFiatPrimaryBalance(getActivity());
            } else {
                SharedPrefUtils.setBitcoinPrimaryBalance(getActivity());
            }
            refreshBalance();
        }
    });

    TextView t1 = (TextView) view.findViewById(R.id.balance_large);
    TextView t2 = (TextView) view.findViewById(R.id.balance_large_currency);
    TextView t3 = (TextView) view.findViewById(R.id.balance_small);
    TextView t4 = (TextView) view.findViewById(R.id.balance_small_currency);

    View.OnLongClickListener listener = new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            DialogFragment fragment = CurrencyDialogFragment.newInstance();
            if (fragment != null) {
                fragment.show(CurrentBalanceFragment.this.getFragmentManager(), TAG);
            }
            return true;
        }
    };

    t1.setOnLongClickListener(listener);
    t2.setOnLongClickListener(listener);
    t3.setOnLongClickListener(listener);
    t4.setOnLongClickListener(listener);
    return view;
}

From source file:odoo.controls.SearchableItemActivity.java

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    mAdapter.getFilter().filter(s);//from  w  w  w  .j  a  va 2s .co  m
    ImageView imgView = (ImageView) findViewById(R.id.search_icon);
    if (s.length() > 0) {
        imgView.setImageResource(R.drawable.ic_action_navigation_close);
        imgView.setOnClickListener(this);
        imgView.setClickable(true);
    } else {
        imgView.setClickable(false);
        imgView.setImageResource(R.drawable.ic_action_search);
        imgView.setOnClickListener(null);
    }
}

From source file:free.yhc.netmbuddy.YTSearchActivity.java

private void setupButton(ImageView iv, int drawable, View.OnClickListener onClick) {
    if (drawable <= 0 || null == onClick) {
        iv.setVisibility(View.GONE);
        iv.setOnClickListener(null);
    } else {/*from  w ww. j  a  v  a 2s  .  c  o  m*/
        iv.setImageResource(drawable);
        iv.setVisibility(View.VISIBLE);
        iv.setOnClickListener(onClick);
    }
}

From source file:com.jhk.whysoformal.activity.musiclist.musicentry.fragment.MusicPlayerFragment.java

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

    View view = inflater.inflate(R.layout.fragment_music_player, container, false);

    updateTitle();/*from w  ww.j  av  a 2s . c om*/

    ImageView mPrevious = (ImageView) view.findViewById(R.id.previous);
    mPrevious.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            sendUpdateMediaPlayerBroadCast(MusicService.UPDATE_MEDIA_PLAYER.PREV, null);
        }
    });

    mPlay = (ImageView) view.findViewById(R.id.play);
    mPlay.setImageResource(android.R.drawable.ic_media_pause);
    mPlay.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            sendUpdateMediaPlayerBroadCast(MusicService.UPDATE_MEDIA_PLAYER.PLAY_PAUSE, null);

            //can be out of sync, but don't want to couple strongly due to tablet
            if (mIsPlaying) {
                mIsPlaying = false;
                mPlay.setImageResource(android.R.drawable.ic_media_play);
                mSeekBarThread.mHandler.sendEmptyMessage(SeekBarThread.PAUSE);
            } else {
                mIsPlaying = true;
                mPlay.setImageResource(android.R.drawable.ic_media_pause);
                mSeekBarThread.mHandler.sendEmptyMessage(SeekBarThread.SEEK_CHANGED);
            }
        }
    });

    ImageView mNext = (ImageView) view.findViewById(R.id.next);
    mNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            sendUpdateMediaPlayerBroadCast(MusicService.UPDATE_MEDIA_PLAYER.NEXT, null);
        }
    });

    mSeekBar = (SeekBar) view.findViewById(R.id.seekBar);
    mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        int progressChanged = 0;

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            mIsDragging = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            float percentage = progressChanged / 100.0f;

            if ((percentage * 100) > SEEK_THRESHOLD) {
                sendUpdateMediaPlayerBroadCast(MusicService.UPDATE_MEDIA_PLAYER.NEXT, null);
            } else {
                Map<String, Float> additional = new HashMap<String, Float>();
                additional.put(MusicService.UPDATE_MEDIA_PLAYER_SEEK_POSITION_KEY, percentage);
                sendUpdateMediaPlayerBroadCast(MusicService.UPDATE_MEDIA_PLAYER.SEEK, additional);
            }

            mIsDragging = false;
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            progressChanged = progress;
        }

    });

    ImageView mLoop = (ImageView) view.findViewById(R.id.loopImage);
    mLoop.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            AudioContext.getInstance().toggleLooping();
        }
    });

    ImageView mShuffle = (ImageView) view.findViewById(R.id.shuffleImage);
    mShuffle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            AudioContext.getInstance().toggleShuffling();
        }
    });

    if (NavUtils.getParentActivityName(getActivity()) != null) {
        getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    return view;
}