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.esri.arcgisruntime.sample.editfeatureattachments.MainActivity.java

/**
 * Create a Layout for callout//from   w w w. j  a v a  2 s  . c  o m
 */
private void createCallout() {

    // create content text view for the callout
    mCalloutLayout = new RelativeLayout(getApplicationContext());
    TextView calloutContent = new TextView(getApplicationContext());
    calloutContent.setId(R.id.calloutTextView);
    calloutContent.setTextColor(Color.BLACK);
    calloutContent.setTextSize(18);

    RelativeLayout.LayoutParams relativeParamsBelow = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relativeParamsBelow.addRule(RelativeLayout.BELOW, calloutContent.getId());

    // create attachment text view for the callout
    TextView calloutAttachment = new TextView(getApplicationContext());
    calloutAttachment.setId(R.id.attchTV);
    calloutAttachment.setTextColor(Color.BLACK);
    calloutAttachment.setTextSize(13);
    calloutContent.setPadding(0, 20, 20, 0);
    calloutAttachment.setLayoutParams(relativeParamsBelow);

    RelativeLayout.LayoutParams relativeParamsRightOf = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relativeParamsRightOf.addRule(RelativeLayout.RIGHT_OF, calloutAttachment.getId());

    // create image view for the callout
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_info));
    imageView.setLayoutParams(relativeParamsRightOf);
    imageView.setOnClickListener(new ImageViewOnclickListener());

    mCalloutLayout.addView(calloutContent);
    mCalloutLayout.addView(imageView);
    mCalloutLayout.addView(calloutAttachment);

}

From source file:com.b44t.ui.Components.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    ImageView tab = new ImageView(getContext());
    tab.setFocusable(true);/*from   w w  w. j  a  va 2 s.com*/
    tab.setImageResource(resId);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
}

From source file:com.birdgang.viewpagerheader.indicator.SpringIndicator.java

private void addTabItems() {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = 30;//w w  w .j a  v a 2  s .c  o  m
    layoutParams.rightMargin = 30;

    tabs = new ArrayList<>();

    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        ImageView imageView = new ImageView(getContext());
        imageView.setImageResource(R.drawable.btn_pop_normal);
        imageView.setLayoutParams(layoutParams);
        final int position = i;
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position)) {
                    viewPager.setCurrentItem(position);
                }
            }
        });

        tabs.add(imageView);
        tabContainer.addView(imageView);
    }
}

From source file:ironblossom.csemock.experimental.utils.SlidingTabLayout.java

private void populateTabIcon() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0,
            LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
    int margin = (int) (10 * ExMainActivity.densityFactor);
    layoutParams.setMargins(0, margin, 0, margin);

    final int[] tabIcons = new int[] { R.drawable.ic_overview, R.drawable.ic_market_info,
            R.drawable.ic_watchlist, R.drawable.ic_portfolio };

    for (int i = 0; i < adapter.getCount(); i++) {
        ImageView tabIconView = new ImageView(getContext());
        tabIconView.setImageResource(tabIcons[i]);
        tabIconView.setLayoutParams(layoutParams);

        tabIconView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabIconView);/*  ww w. jav a2 s .  c  o  m*/

    }
}

From source file:com.tony.babygo.adapter.ImagePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView imageView = new ImageView(context);

    Business business = businesses.getBusinesses().get(position);
    Bitmap bitmap = Bimp.getBitmapFromMemoryCache(business.getPhoto_url());
    if (bitmap != null) {
        imageView.setImageBitmap(bitmap);
    } else {/*  w  ww .  ja  va  2  s  . c  o  m*/
        imageView.setImageResource(imageIdList.get(0));
    }

    ((ViewPager) container).addView(imageView, 0);
    imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent goBrowserIntent = new Intent(context, MyBrowserActivity.class);
            goBrowserIntent.putExtra("html5url",
                    businesses.getBusinesses().get(DianpingUserData.cur_scroll_page_index).getBusiness_url());
            context.startActivity(goBrowserIntent);
        }
    });
    return imageView;
}

From source file:com.knurld.alphabank.LoginActivity.java

private void setupViews() {

    KnurldRequestHelper.initApp(getResources());
    //invalidate cache
    KnurldRequestHelper.invalidateCache();
    etUsername = (EditText) findViewById(R.id.etUsername);
    etPassword = (EditText) findViewById(R.id.etPassword);

    Button loginButton = (Button) findViewById(R.id.btnSignin);
    //Button registerButton = (Button) findViewById(R.id.btnRegister);

    ImageView imageButton = (ImageView) findViewById(R.id.knurld_logo);

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w  w  . j a va2  s  .c  o m*/
        public void onClick(View v) {
            KnurldRequestHelper.invalidateCache();
            Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
            startActivity(intent);
        }
    });

    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String username = etUsername.getText().toString().trim();
            if (username.isEmpty()) {
                Toast.makeText(getApplicationContext(), "Enter username", Toast.LENGTH_SHORT).show();
                return;
            }

            String password = etPassword.getText().toString().trim();
            if (password.isEmpty()) {
                Toast.makeText(getApplicationContext(), "Enter password", Toast.LENGTH_SHORT).show();
                return;
            }
            if (!KnurldRequestHelper.checkInternetConnection(LoginActivity.this)) {
                return;
            }

            Response.Listener<JSONObject> responseListner = new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        String token = response.getString("token");
                        KnurldRequestHelper.developerId = KnurldRequestHelper.knurldBearerConst + token;
                        KnurldRequestHelper.USERNAME = username;

                        checkUserIsValid(username);
                    } catch (JSONException e) {
                        progressDialog.dismiss();
                        if (AlphaBankUtil.debug)
                            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }

            };

            Response.ErrorListener errorListener = new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    String message = KnurldRequestHelper
                            .getErrorMessage(KnurldRequestHelper.formatVolleyErrorResponse(error));
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(LoginActivity.this);
                    alertDialog.setTitle("User Login failed").setMessage(message).setCancelable(true)
                            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                }
                            });
                    alertDialog.create().show();
                    progressDialog.dismiss();
                }
            };

            JSONObject parameters = new JSONObject();
            try {
                parameters.accumulate("username", username);
                parameters.accumulate("password", password);
            } catch (JSONException jse) {
            }
            //RequestQueue requestQueue = Volley.newRequestQueue(LoginActivity.this);
            CustomRequest jsObjRequest = new CustomRequest(Request.Method.POST,
                    KnurldRequestHelper.USER_LOGIN_URL, parameters.toString(), responseListner, errorListener);

            //showing loading dialog
            progressDialog = new ProgressDialog(LoginActivity.this);
            progressDialog.setTitle("Login");
            progressDialog.setMessage("Please wait while we validate your credentials");
            progressDialog.setCancelable(false);

            progressDialog.show();

            //                if (!KnurldRequestHelper.isUserLoggedIn()) {
            //                    KnurldRequestHelper.Login(LoginActivity.this, jsObjRequest);
            //                } else {
            //                    requestQueue.add(jsObjRequest);
            //                }
            AlphaRequestQueue.submit(LoginActivity.this, jsObjRequest, true);
        }
    });

    //        registerButton.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View v) {
    //                KnurldRequestHelper.invalidateCache();
    //                Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
    //                startActivity(intent);
    //            }
    //        });

    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                AlphaBankUtil.REQUEST_WRITE_STORAGE);
        return;
    }
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO },
                AlphaBankUtil.REQUEST_RECORD_AUDIO);
        return;
    }

}

From source file:joshuatee.wx.MiscFragment.java

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

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

    state_code_current = preferences.getString("STATE_CODE", "");
    twitter_state_id = preferences.getString("STATE_TW_ID_" + state_code_current, "");

    DisplayMetrics dm = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);

    ImageView iv_1 = (ImageView) view.findViewById(R.id.iv_1);
    iv_1.setOnClickListener(this);
    ImageView iv_2 = (ImageView) view.findViewById(R.id.iv_2);
    iv_2.setOnClickListener(this);
    ImageView iv_3 = (ImageView) view.findViewById(R.id.iv_3);
    iv_3.setOnClickListener(this);
    ImageView iv_4 = (ImageView) view.findViewById(R.id.iv_4);
    iv_4.setOnClickListener(this);
    ImageView iv_5 = (ImageView) view.findViewById(R.id.iv_5);
    iv_5.setOnClickListener(this);
    ImageView iv_6 = (ImageView) view.findViewById(R.id.iv_6);
    iv_6.setOnClickListener(this);
    ImageView iv_7 = (ImageView) view.findViewById(R.id.iv_7);
    iv_7.setOnClickListener(this);
    ImageView iv_8 = (ImageView) view.findViewById(R.id.iv_8);
    iv_8.setOnClickListener(this);
    ImageView iv_9 = (ImageView) view.findViewById(R.id.iv_9);
    iv_9.setOnClickListener(this);
    ImageView iv_10 = (ImageView) view.findViewById(R.id.iv_10);
    iv_10.setOnClickListener(this);
    ImageView iv_11 = (ImageView) view.findViewById(R.id.iv_11);
    iv_11.setOnClickListener(this);
    ImageView iv_12 = (ImageView) view.findViewById(R.id.iv_12);
    iv_12.setOnClickListener(this);

    LayoutParams params_iv = null;//from   ww  w  .jav  a2  s .  com
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.models), iv_1, 3,
            params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.srfd), iv_2, 3, params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.nexrad_attr), iv_3, 3,
            params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.warn), iv_4, 3, params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.warn_cod), iv_5, 3,
            params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.nhc), iv_6, 3, params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.nws_sector), iv_7, 3,
            params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.goes), iv_8, 3, params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.lightning), iv_9, 3,
            params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.twstate), iv_10, 3,
            params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.twwu), iv_11, 3, params_iv);
    UtilityImg.ResizeViewSetImgTile(dm, UtilityImg.LoadBM(getActivity(), R.drawable.twtornado), iv_12, 3,
            params_iv);

    registerForContextMenu(iv_1);
    registerForContextMenu(iv_7);
    registerForContextMenu(iv_8);
    registerForContextMenu(iv_9);
    registerForContextMenu(iv_10);

    spinner1 = (Spinner) view.findViewById(R.id.spinner1);

    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, fmap_label);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner1.setAdapter(dataAdapter);
    spinner1.setOnItemSelectedListener(this);

    spinner2 = (Spinner) view.findViewById(R.id.spinner2);

    ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, qpf_label);
    dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner2.setAdapter(dataAdapter2);
    spinner2.setOnItemSelectedListener(this);

    return view;
}

From source file:galilei.kelimekavanozu.activity.PoemBuilderActivity.java

private void setUpBack() {
    // go back if clicked
    final ImageView backButton = (ImageView) findViewById(R.id.back);
    backButton.setOnClickListener(new View.OnClickListener() {
        @Override//from  w  ww  .ja va  2 s .co  m
        public void onClick(View v) {
            onBackPressed();
        }
    });
}

From source file:net.jongrakko.zipsuri.fragment.PostDetailExpertFragment1.java

private void setVideo() {
    ImageView videoView = (ImageView) rootView.findViewById(R.id.imageViewVideo);
    if (mPostModel.getVideo() == null) {
        videoView.setVisibility(View.GONE);
    } else {// w  ww . ja  va 2s  . c  o  m
        videoView.setImageResource(R.drawable.ic_play_circle_outline_white_48dp);
        videoView.setOnClickListener(this);

    }
}

From source file:com.microsoft.AzureIntelligentServicesExample.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this._logText = (EditText) findViewById(R.id.editText1);
    this._startButton = (Button) findViewById(R.id.button1);

    tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override/*www  .  ja  va  2s . co m*/
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {

                int result = tts.setLanguage(Locale.US);
                if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    Log.e("TTS", "This Language is not supported");
                    Intent installIntent = new Intent();
                    installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                    startActivity(installIntent);
                }
            } else {
                Log.e("TTS", "Initilization Failed!");
            }
        }
    });

    ImageView sendBtn = (ImageView) findViewById(R.id.sendBtn);
    final EditText message = (EditText) findViewById(R.id.message);

    sendBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {

            _logText.append("ME : " + message.getText().toString() + "\n");
            speakOut(message.getText().toString());
            message.setText("");
        }
    });

    if (getString(R.string.primaryKey).startsWith("Please")) {
        new AlertDialog.Builder(this).setTitle(getString(R.string.add_subscription_key_tip_title))
                .setMessage(getString(R.string.add_subscription_key_tip)).setCancelable(false).show();
    }

    // setup the buttons
    final MainActivity This = this;
    this._startButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            This.StartButton_Click(arg0);
        }
    });

}