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.dsdar.thosearoundme.TeamViewActivity.java

@Override
public boolean onMarkerClick(final Marker theMarker) {
    if (theMarker.equals(MyAppConstants.myMarker)) {
        return false;
    }//from   w  w w. j av a2s.  c o  m

    // Normal Marker
    if (!theMarker.equals(MyAppConstants.myMarker) && (theMarker.getTitle() != null)) {

        final Dialog aMemberDialog = new Dialog(TeamViewActivity.this, R.style.DialogSlideAnim);
        aMemberDialog.setContentView(R.layout.member_dialog);

        TextView aMemberTextName = (TextView) aMemberDialog.findViewById(R.id.tvMemberName);
        Button aTextButton = (Button) aMemberDialog.findViewById(R.id.bMemberText);
        Button aPushButton = (Button) aMemberDialog.findViewById(R.id.bMemberPush);
        Button aCallButton = (Button) aMemberDialog.findViewById(R.id.bMemberCall);
        Button aRemoveButton = (Button) aMemberDialog.findViewById(R.id.bMemberRemove);

        String[] res = theMarker.getTitle().split("~");
        String title = res[0];
        final String phone = res[1];

        aMemberTextName.setText("Say hello to " + title + "!");
        aMemberDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        aMemberDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        aMemberDialog.getWindow().setGravity(Gravity.BOTTOM);
        aMemberDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        aMemberDialog.show();
        ImageView aCancelButton = (ImageView) aMemberDialog.findViewById(R.id.bCancelMemberDialog);
        aCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                aMemberDialog.dismiss();
            }
        });

        aTextButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Uri sms_uri = Uri.parse("smsto:" + phone);
                Intent sms_intent = new Intent(Intent.ACTION_SENDTO, sms_uri);
                startActivity(sms_intent);
            }
        });

        // aPushButton.setOnClickListener(new OnClickListener() {
        // public void onClick(View v) {
        // // startActivity(new Intent(Intent.ACTION_VIEW,
        // // Uri.parse("sms:"
        // // + theMarker.getSnippet())));
        // }
        // });

        aCallButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent callIntent = new Intent(Intent.ACTION_DIAL);
                callIntent.setData(Uri.parse("tel:" + phone));
                startActivity(callIntent);
            }
        });

        // aRemoveButton.setOnClickListener(new OnClickListener() {
        // public void onClick(View v) {
        // }
        // });
    } else {

        StickyMarkerBehaviorDialog dialog = new StickyMarkerBehaviorDialog(this);
        dialog.show();
    }

    return true;
}

From source file:com.retroteam.studio.retrostudio.MeasureEditor.java

/**
 * Draw the grid./*w  w  w  . ja  va2 s .  com*/
 */
private void drawGrid() {
    //draw the grid based on project info
    thisMeasure = theproject.track(trackNum).measure(measureNum);
    TableLayout notedraw = (TableLayout) findViewById(R.id.notedraw);
    int notedrawlen = notedraw.getChildCount();

    //get note scale
    final float dscale = getApplicationContext().getResources().getDisplayMetrics().density;
    int notewidth = (int) (144 * dscale + 0.5f);
    int noteheight = (int) (75 * dscale + 0.5f);

    for (int x = 0; x < notedrawlen; x++) {
        TableRow noterow = (TableRow) notedraw.getChildAt(x);
        List<List<Integer>> rangelist = numNotesFromGuiSnap();
        for (int i = 0; i < rangelist.size(); i++) {
            ImageView note = new ImageView(getApplicationContext());
            note.setLayoutParams(new TableRow.LayoutParams(notewidth, noteheight));

            note.setTag(R.id.TAG_ROW, x);
            note.setTag(R.id.TAG_COLUMN, i);
            note.setTag(R.id.TAG_NOTE, notesdisplay[x]);

            note.setTag(R.id.TAG_GUISNAPRANGE, rangelist.get(i));

            note.setImageResource(R.drawable.measure_outline);
            if (filledNotesFromIntent.size() > 0) {
                for (int z = 0; z < filledNotesFromIntent.size(); z++) {
                    if ((filledNotesFromIntent.get(z)[0] == x) && (filledNotesFromIntent.get(z)[1] == i)) {
                        note.setImageResource(R.drawable.note_filled);
                    }
                }
            }

            note.setBackgroundColor(getResources().getColor(R.color.note_rest));

            note.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    paintNote(v);

                }
            });

            noterow.addView(note);
        }
    }
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionDetailFragment.java

private void onSpeakersQueryComplete(Cursor cursor) {
    mSpeakersCursor = true;//from   w  ww.  j a va  2  s.c o  m
    final ViewGroup speakersGroup = (ViewGroup) mRootView.findViewById(R.id.session_speakers_block);

    // Remove all existing speakers (everything but first child, which is the header)
    for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) {
        speakersGroup.removeViewAt(i);
    }

    final LayoutInflater inflater = getActivity().getLayoutInflater();

    boolean hasSpeakers = false;

    while (cursor.moveToNext()) {
        final String speakerName = cursor.getString(SpeakersQuery.SPEAKER_NAME);
        if (TextUtils.isEmpty(speakerName)) {
            continue;
        }

        final String speakerImageUrl = cursor.getString(SpeakersQuery.SPEAKER_IMAGE_URL);
        final String speakerCompany = cursor.getString(SpeakersQuery.SPEAKER_COMPANY);
        final String speakerUrl = cursor.getString(SpeakersQuery.SPEAKER_URL);
        final String speakerAbstract = cursor.getString(SpeakersQuery.SPEAKER_ABSTRACT);

        String speakerHeader = speakerName;
        if (!TextUtils.isEmpty(speakerCompany)) {
            speakerHeader += ", " + speakerCompany;
        }

        final View speakerView = inflater.inflate(R.layout.speaker_detail, speakersGroup, false);
        final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.speaker_header);
        final ImageView speakerImageView = (ImageView) speakerView.findViewById(R.id.speaker_image);
        final TextView speakerAbstractView = (TextView) speakerView.findViewById(R.id.speaker_abstract);

        if (!TextUtils.isEmpty(speakerImageUrl) && mImageLoader != null) {
            mImageLoader.get(UIUtils.getConferenceImageUrl(speakerImageUrl), speakerImageView);
        }

        speakerHeaderView.setText(speakerHeader);
        speakerImageView.setContentDescription(getString(R.string.speaker_googleplus_profile, speakerHeader));
        UIUtils.setTextMaybeHtml(speakerAbstractView, speakerAbstract);

        if (!TextUtils.isEmpty(speakerUrl)) {
            speakerImageView.setEnabled(true);
            speakerImageView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(speakerUrl));
                    speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    UIUtils.preferPackageForIntent(getActivity(), speakerProfileIntent,
                            UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                    startActivity(speakerProfileIntent);
                }
            });
        } else {
            speakerImageView.setEnabled(false);
            speakerImageView.setOnClickListener(null);
        }

        speakersGroup.addView(speakerView);
        hasSpeakers = true;
        mHasSummaryContent = true;
    }

    speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE);

    // Show empty message when all data is loaded, and nothing to show
    if (mSessionCursor && !mHasSummaryContent) {
        mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    }
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void initBrushColor() {
    Resources res = getResources();

    final int size = 4 * 3;
    int[] btn_id = new int[size];
    btn_id[0] = R.id.btn_color_11;//from   w  ww.j a va  2s.  c o  m
    btn_id[1] = R.id.btn_color_12;
    btn_id[2] = R.id.btn_color_13;
    btn_id[3] = R.id.btn_color_14;
    btn_id[4] = R.id.btn_color_21;
    btn_id[5] = R.id.btn_color_22;
    btn_id[6] = R.id.btn_color_23;
    btn_id[7] = R.id.btn_color_24;
    btn_id[8] = R.id.btn_color_31;
    btn_id[9] = R.id.btn_color_32;
    btn_id[10] = R.id.btn_color_33;
    btn_id[11] = R.id.btn_color_34;

    int[] color_id = new int[size];
    color_id[0] = R.color.palette_color_11;
    color_id[1] = R.color.palette_color_12;
    color_id[2] = R.color.palette_color_13;
    color_id[3] = R.color.palette_color_14;
    color_id[4] = R.color.palette_color_21;
    color_id[5] = R.color.palette_color_22;
    color_id[6] = R.color.palette_color_23;
    color_id[7] = R.color.palette_color_24;
    color_id[8] = R.color.palette_color_31;
    color_id[9] = R.color.palette_color_32;
    color_id[10] = R.color.palette_color_33;
    color_id[11] = R.color.palette_color_34;

    if (res != null) {
        ImageView button = null;
        GradientDrawable drawable = null;
        for (int i = 0; i < size; i++) {
            button = (ImageView) mPalette.findViewById(btn_id[i]);
            if (button != null) {
                drawable = (GradientDrawable) button.getDrawable();
                drawable.setColor(res.getColor(color_id[i]));
                mBtnColor.put(btn_id[i], res.getColor(color_id[i]));
                button.setOnClickListener(mButtonListener);

                if (i == 0) {
                    mCurrBrushColorView = button;
                    mCurrBrushColor = res.getColor(color_id[i]);
                    setSelectedColor(mCurrBrushColorView);
                }
            }
        }
    }
}

From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java

public void refreshActionBarColumns() {

    int currentPosition = pager.getCurrentItem();

    layoutBackgroundColumnsBar.removeAllViews();

    int padding = (int) getResources().getDimension(R.dimen.default_padding);
    //int sizeButton = (int) getResources().getDimension(R.dimen.actionbar_columns_height);

    for (int i = 1; i < fragmentAdapter.getFragmentList().size(); i++) {

        ImageView view = new ImageView(this);
        view.setPadding(padding, padding, padding, padding);
        view.setImageBitmap(ColumnsUtils.getButtonWithTitle(this, fragmentAdapter.getFragmentList().get(i),
                true, currentPosition == i ? Color.GREEN : Color.BLACK));
        view.setTag(i);/*  w  ww .  j  a v a 2  s . co  m*/
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (layoutMainOptionsColumns.getVisibility() != View.VISIBLE) {
                    showActionBarIndicatorAndMovePager((Integer) view.getTag());
                }
            }
        });
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                int pos = (Integer) view.getTag();
                int[] loc = new int[2];
                view.getLocationOnScreen(loc);
                showOptionsColumns(loc[0], pos, true);
                return false;
            }
        });
        layoutBackgroundColumnsBar.addView(view);
    }
}

From source file:de.grobox.liberario.DirectionsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // remember view for UI changes when fragment is not active
    mView = inflater.inflate(R.layout.fragment_directions, container, false);
    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    checkPreferences();/*from  w w w. j av  a2 s . co  m*/

    setFromUI();
    setToUI();

    // timeView
    final Button timeView = (Button) mView.findViewById(R.id.timeView);
    timeView.setText(DateUtils.getcurrentTime(getActivity()));
    timeView.setTag(Calendar.getInstance());
    timeView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showTimePickerDialog();
        }
    });

    // set current time on long click
    timeView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            timeView.setText(DateUtils.getcurrentTime(getActivity()));
            timeView.setTag(Calendar.getInstance());
            return true;
        }
    });

    Button plus10Button = (Button) mView.findViewById(R.id.plus15Button);
    plus10Button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            addToTime(15);
        }
    });

    // dateView
    final Button dateView = (Button) mView.findViewById(R.id.dateView);
    dateView.setText(DateUtils.getcurrentDate(getActivity()));
    dateView.setTag(Calendar.getInstance());
    dateView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showDatePickerDialog();
        }
    });

    // set current date on long click
    dateView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            dateView.setText(DateUtils.getcurrentDate(getActivity()));
            dateView.setTag(Calendar.getInstance());
            return true;
        }
    });

    // Trip Date Type Spinner (departure or arrival)
    final TextView dateType = (TextView) mView.findViewById(R.id.dateType);
    dateType.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (dateType.getText().equals(getString(R.string.trip_dep))) {
                dateType.setText(getString(R.string.trip_arr));
            } else {
                dateType.setText(getString(R.string.trip_dep));
            }
        }
    });

    // Products
    final ViewGroup productsLayout = (ViewGroup) mView.findViewById(R.id.productsLayout);
    for (int i = 0; i < productsLayout.getChildCount(); ++i) {
        final ImageView productView = (ImageView) productsLayout.getChildAt(i);
        final Product product = Product.fromCode(productView.getTag().toString().charAt(0));

        // make inactive products gray
        if (mProducts.contains(product)) {
            productView.getDrawable().setColorFilter(null);
        } else {
            productView.getDrawable().setColorFilter(getResources().getColor(R.color.highlight),
                    PorterDuff.Mode.SRC_ATOP);
        }

        // handle click on product icon
        productView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (mProducts.contains(product)) {
                    productView.getDrawable().setColorFilter(getResources().getColor(R.color.highlight),
                            PorterDuff.Mode.SRC_ATOP);
                    mProducts.remove(product);
                    Toast.makeText(v.getContext(), LiberarioUtils.productToString(v.getContext(), product),
                            Toast.LENGTH_SHORT).show();
                } else {
                    productView.getDrawable().setColorFilter(null);
                    mProducts.add(product);
                    Toast.makeText(v.getContext(), LiberarioUtils.productToString(v.getContext(), product),
                            Toast.LENGTH_SHORT).show();
                }
            }
        });

        // handle long click on product icon by showing product name
        productView.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                Toast.makeText(view.getContext(), LiberarioUtils.productToString(view.getContext(), product),
                        Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }

    if (!Preferences.getPref(getActivity(), Preferences.SHOW_ADV_DIRECTIONS)) {
        (mView.findViewById(R.id.productsScrollView)).setVisibility(View.GONE);
    }

    Button searchButton = (Button) mView.findViewById(R.id.searchButton);
    searchButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            NetworkProvider np = NetworkProviderFactory.provider(Preferences.getNetworkId(getActivity()));
            if (!np.hasCapabilities(NetworkProvider.Capability.TRIPS)) {
                Toast.makeText(v.getContext(), v.getContext().getString(R.string.error_no_trips_capability),
                        Toast.LENGTH_SHORT).show();
                return;
            }

            AsyncQueryTripsTask query_trips = new AsyncQueryTripsTask(v.getContext());

            // check and set to location
            if (checkLocation(FavLocation.LOC_TYPE.TO)) {
                query_trips.setTo(getLocation(FavLocation.LOC_TYPE.TO));
            } else {
                Toast.makeText(getActivity(), getResources().getString(R.string.error_invalid_to),
                        Toast.LENGTH_SHORT).show();
                return;
            }

            // check and set from location
            if (mGpsPressed) {
                if (getLocation(FavLocation.LOC_TYPE.FROM) != null) {
                    query_trips.setFrom(getLocation(FavLocation.LOC_TYPE.FROM));
                } else {
                    mAfterGpsTask = query_trips;

                    pd = new ProgressDialog(getActivity());
                    pd.setMessage(getResources().getString(R.string.stations_searching_position));
                    pd.setCancelable(false);
                    pd.setIndeterminate(true);
                    pd.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    mAfterGpsTask = null;
                                    dialog.dismiss();
                                }
                            });
                    pd.show();
                }
            } else {
                if (checkLocation(FavLocation.LOC_TYPE.FROM)) {
                    query_trips.setFrom(getLocation(FavLocation.LOC_TYPE.FROM));
                } else {
                    Toast.makeText(getActivity(), getString(R.string.error_invalid_from), Toast.LENGTH_SHORT)
                            .show();
                    return;
                }
            }

            // remember trip if not from GPS
            if (!mGpsPressed) {
                FavDB.updateFavTrip(getActivity(), new FavTrip(getLocation(FavLocation.LOC_TYPE.FROM),
                        getLocation(FavLocation.LOC_TYPE.TO)));
            }

            // set date
            query_trips.setDate(DateUtils.mergeDateTime(getActivity(), dateView.getText(), timeView.getText()));

            // set departure to true of first item is selected in spinner
            query_trips.setDeparture(dateType.getText().equals(getString(R.string.trip_dep)));

            // set products
            query_trips.setProducts(mProducts);

            // don't execute if we still have to wait for GPS position
            if (mAfterGpsTask != null)
                return;

            query_trips.execute();
        }
    });

    return mView;
}

From source file:com.example.nikhil.wikipediasearch.ImageAdapter.java

private void zoomImageFromThumb(final View thumbView, int imageId) {
    // If there's an animation in progress, cancel it immediately and
    // proceed with this one.
    int startIndex = 0;
    int lastIndex = 0;

    // Load the high-resolution "zoomed-in" image.
    final ImageView expandedImageView = (ImageView) ((Activity) thumbView.getContext())
            .findViewById(R.id.expanded_image);

    expandedImageView.setBackgroundColor(ContextCompat.getColor(thumbView.getContext(), R.color.Color_1));
    String newURL = URLS[imageId].replace("/thumb", "");

    lastIndex = newURL.lastIndexOf("/");

    String newURLSubString = newURL.substring(lastIndex);

    newURL = newURL.replace(newURLSubString, "");

    int width = thumbView.getContext().getResources().getDisplayMetrics().widthPixels;
    int height = thumbView.getContext().getResources().getDisplayMetrics().heightPixels;

    Picasso.with(thumbView.getContext()).load(newURL).noFade().resize(width, height / 2).centerCrop()
            .error(R.drawable.no_image).placeholder(R.drawable.progress_animation)
            .into((ImageView) expandedImageView);

    Log.d(TAG, "setOnClickListener" + newURL);

    expandedImageView.setVisibility(View.VISIBLE);

    // Set the pivot point for SCALE_X and SCALE_Y transformations to the
    // top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);//from  w w w .  j  a v a 2 s  . co  m
    expandedImageView.setPivotY(0f);

    // Upon clicking the zoomed-in image, it should zoom back down to the
    // original bounds
    // and show the thumbnail instead of the expanded image.
    //final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            expandedImageView.setVisibility(View.GONE);
        }
    });
}

From source file:com.example.angel.parkpanda.MainActivity.java

void initGUI() {
    initNavWindow();/*ww  w.j a va2s .  c  o  m*/
    initViewSetting(true);
    showhideFootWindow(0);

    tv = (TextView) findViewById(R.id.txt_error_text);
    tv.setText("");

    ImageView iv_search = (ImageView) findViewById(R.id.toolbar_search);
    ImageView iv_control = (ImageView) findViewById(R.id.toolbar_control);
    ImageView iv_prev = (ImageView) findViewById(R.id.toolbar_prev);
    ImageView iv_nav = (ImageView) findViewById(R.id.bottom_toolbar_nav);

    Button btn_payment = (Button) findViewById(R.id.reserve_button);
    if (checkAlradyLogin() == 1) {
        btn_payment.setEnabled(true);
    } else {
        btn_payment.setEnabled(false);
    }

    // iv_bottm_toolbar_control=(ImageView)findViewById(R.id.image_bottom_toolbar_control);
    // iv_bottm_toolbar_control.setOnClickListener(this);
    btn_payment.setOnClickListener(this);
    iv_control.setOnClickListener(this);
    iv_prev.setOnClickListener(this);
    iv_search.setOnClickListener(this);
    iv_nav.setOnClickListener(this);

    FacebookSdk.sdkInitialize(getApplicationContext());

}

From source file:de.baumann.hhsmoodle.data_subjects.Subjects_Fragment.java

private void setSubjectsList() {

    final helper_main.Item[] items = {
            new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red),
            new helper_main.Item(getString(R.string.subjects_color_pink), R.drawable.circle_pink),
            new helper_main.Item(getString(R.string.subjects_color_purple), R.drawable.circle_purple),
            new helper_main.Item(getString(R.string.subjects_color_blue), R.drawable.circle_blue),
            new helper_main.Item(getString(R.string.subjects_color_teal), R.drawable.circle_teal),
            new helper_main.Item(getString(R.string.subjects_color_green), R.drawable.circle_green),
            new helper_main.Item(getString(R.string.subjects_color_lime), R.drawable.circle_lime),
            new helper_main.Item(getString(R.string.subjects_color_yellow), R.drawable.circle_yellow),
            new helper_main.Item(getString(R.string.subjects_color_orange), R.drawable.circle_orange),
            new helper_main.Item(getString(R.string.subjects_color_brown), R.drawable.circle_brown),
            new helper_main.Item(getString(R.string.subjects_color_grey), R.drawable.circle_grey), };

    //display data
    final int layoutstyle = R.layout.list_item_schedule;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes };
    String[] column = new String[] { "subject_title", "subject_content", "subject_attachment" };
    final Cursor row = db.fetchAllData();
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override//from  w  w  w  .  j a  v a  2 s. com
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row = (Cursor) lv.getItemAtPosition(position);
            final String _id = row.getString(row.getColumnIndexOrThrow("_id"));
            final String subject_title = row.getString(row.getColumnIndexOrThrow("subject_title"));
            final String subject_content = row.getString(row.getColumnIndexOrThrow("subject_content"));
            final String subject_icon = row.getString(row.getColumnIndexOrThrow("subject_icon"));
            final String subject_attachment = row.getString(row.getColumnIndexOrThrow("subject_attachment"));
            final String subject_creation = row.getString(row.getColumnIndexOrThrow("subject_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", iv_icon);
            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "1",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "2",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "3",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 3) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "4",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 4) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "5",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 5) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "6",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 6) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "7",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 7) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "8",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 8) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "9",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 9) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "10",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    } else if (item == 10) {
                                        db.update(Integer.parseInt(_id), subject_title, subject_content, "11",
                                                subject_attachment, subject_creation);
                                        setSubjectsList();
                                    }
                                }
                            }).show();
                }
            });

            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String subject_title = row2.getString(row2.getColumnIndexOrThrow("subject_title"));
            final String subject_content = row2.getString(row2.getColumnIndexOrThrow("subject_content"));

            final CharSequence[] options = { getString(R.string.courseList_todo),
                    getString(R.string.courseList_note), getString(R.string.courseList_random),
                    getString(R.string.courseList_course), getString(R.string.bookmark_createEvent) };

            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.courseList_random))) {

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(subject_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.number_edit_entry);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();

                                dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE)
                                        .setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //Do stuff, possibly set wantToCloseDialog to true then...
                                                Random_DbAdapter db = new Random_DbAdapter(getActivity());
                                                db.open();

                                                if (db.isExist(subject_title)) {
                                                    Snackbar.make(edit_title,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    String inputTitle = edit_title.getText().toString().trim();
                                                    String inputCont = edit_cont.getText().toString().trim();
                                                    db.insert(inputTitle, inputCont, "", "",
                                                            helper_main.createDate());
                                                    dialog2.cancel();
                                                }
                                            }
                                        });
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.courseList_note))) {
                                Notes_helper.newNote(getActivity(), subject_title, subject_content, "", "", "",
                                        "");
                            }

                            if (options[item].equals(getString(R.string.courseList_todo))) {
                                Todo_helper.newTodo(getActivity(), subject_title, subject_content,
                                        getActivity().getString(R.string.note_content));
                            }

                            if (options[item].equals(getString(R.string.courseList_course))) {

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(subject_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.number_edit_entry);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();

                                dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE)
                                        .setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //Do stuff, possibly set wantToCloseDialog to true then...
                                                Courses_DbAdapter db = new Courses_DbAdapter(getActivity());
                                                db.open();

                                                if (db.isExist(subject_title)) {
                                                    Snackbar.make(edit_title,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    String inputTitle = edit_title.getText().toString().trim();
                                                    String inputCont = edit_cont.getText().toString().trim();
                                                    db.insert(inputTitle, inputCont, "", "",
                                                            helper_main.createDate());
                                                    dialog2.cancel();
                                                }
                                            }
                                        });
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), subject_title, subject_content);
                            }

                        }
                    }).show();
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String subject_title = row2.getString(row2.getColumnIndexOrThrow("subject_title"));
            final String subject_content = row2.getString(row2.getColumnIndexOrThrow("subject_content"));
            final String subject_icon = row2.getString(row2.getColumnIndexOrThrow("subject_icon"));
            final String subject_attachment = row2.getString(row2.getColumnIndexOrThrow("subject_attachment"));
            final String subject_creation = row2.getString(row2.getColumnIndexOrThrow("subject_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.subjects_copy), getString(R.string.bookmark_remove_bookmark) };
            new android.app.AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {

                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                LayoutInflater inflater = getActivity().getLayoutInflater();

                                final ViewGroup nullParent = null;
                                View dialogView = inflater.inflate(R.layout.dialog_edit_subject, nullParent);

                                titleInput = (EditText) dialogView.findViewById(R.id.subject_title_);
                                titleInput.setSelection(titleInput.getText().length());
                                titleInput.setText(subject_title);
                                teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher);
                                teacherInput.setText(subject_content);
                                roomInput = (EditText) dialogView.findViewById(R.id.subject_room);
                                roomInput.setText(subject_attachment);

                                helper_main.showKeyboard(getActivity(), titleInput);

                                final ImageButton be = (ImageButton) dialogView
                                        .findViewById(R.id.imageButtonPri);
                                assert be != null;
                                Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", be);

                                be.setOnClickListener(new View.OnClickListener() {

                                    @Override
                                    public void onClick(View arg0) {

                                        ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                                                android.R.layout.select_dialog_item, android.R.id.text1,
                                                items) {
                                            @NonNull
                                            public View getView(int position, View convertView,
                                                    @NonNull ViewGroup parent) {
                                                //Use super class to create the View
                                                View v = super.getView(position, convertView, parent);
                                                TextView tv = (TextView) v.findViewById(android.R.id.text1);
                                                tv.setTextSize(18);
                                                tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon,
                                                        0, 0, 0);
                                                //Add margin between image and text (support various screen densities)
                                                int dp5 = (int) (24 * getActivity().getResources()
                                                        .getDisplayMetrics().density + 0.5f);
                                                tv.setCompoundDrawablePadding(dp5);

                                                return v;
                                            }
                                        };

                                        new android.app.AlertDialog.Builder(getActivity())
                                                .setPositiveButton(R.string.toast_cancel,
                                                        new DialogInterface.OnClickListener() {

                                                            public void onClick(DialogInterface dialog,
                                                                    int whichButton) {
                                                                dialog.cancel();
                                                            }
                                                        })
                                                .setAdapter(adapter, new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int item) {
                                                        if (item == 0) {
                                                            be.setImageResource(R.drawable.circle_red);
                                                            sharedPref.edit().putString("subject_color", "1")
                                                                    .apply();
                                                        } else if (item == 1) {
                                                            be.setImageResource(R.drawable.circle_pink);
                                                            sharedPref.edit().putString("subject_color", "2")
                                                                    .apply();
                                                        } else if (item == 2) {
                                                            be.setImageResource(R.drawable.circle_purple);
                                                            sharedPref.edit().putString("subject_color", "3")
                                                                    .apply();
                                                        } else if (item == 3) {
                                                            be.setImageResource(R.drawable.circle_blue);
                                                            sharedPref.edit().putString("subject_color", "4")
                                                                    .apply();
                                                        } else if (item == 4) {
                                                            be.setImageResource(R.drawable.circle_teal);
                                                            sharedPref.edit().putString("subject_color", "5")
                                                                    .apply();
                                                        } else if (item == 5) {
                                                            be.setImageResource(R.drawable.circle_green);
                                                            sharedPref.edit().putString("subject_color", "6")
                                                                    .apply();
                                                        } else if (item == 6) {
                                                            be.setImageResource(R.drawable.circle_lime);
                                                            sharedPref.edit().putString("subject_color", "7")
                                                                    .apply();
                                                        } else if (item == 7) {
                                                            be.setImageResource(R.drawable.circle_yellow);
                                                            sharedPref.edit().putString("subject_color", "8")
                                                                    .apply();
                                                        } else if (item == 8) {
                                                            be.setImageResource(R.drawable.circle_orange);
                                                            sharedPref.edit().putString("subject_color", "9")
                                                                    .apply();
                                                        } else if (item == 9) {
                                                            be.setImageResource(R.drawable.circle_brown);
                                                            sharedPref.edit().putString("subject_color", "10")
                                                                    .apply();
                                                        } else if (item == 10) {
                                                            be.setImageResource(R.drawable.circle_grey);
                                                            sharedPref.edit().putString("subject_color", "11")
                                                                    .apply();
                                                        }
                                                    }
                                                }).show();
                                    }
                                });

                                android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                                        getActivity());
                                builder.setTitle(R.string.subjects_edit);
                                builder.setView(dialogView);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                Subject_DbAdapter db = new Subject_DbAdapter(getActivity());
                                                db.open();

                                                String inputTitle = titleInput.getText().toString().trim();
                                                String inputTeacher = teacherInput.getText().toString().trim();
                                                String inputRoom = roomInput.getText().toString().trim();

                                                db.update(Integer.parseInt(_id), inputTitle, inputTeacher,
                                                        sharedPref.getString("subject_color", ""), inputRoom,
                                                        subject_creation);
                                                dialog.dismiss();
                                                setSubjectsList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.support.v7.app.AlertDialog dialog2 = builder.create();
                                dialog2.show();
                            }

                            if (options[item].equals(getString(R.string.subjects_copy))) {

                                LayoutInflater inflater = getActivity().getLayoutInflater();

                                final ViewGroup nullParent = null;
                                View dialogView = inflater.inflate(R.layout.dialog_edit_subject, nullParent);

                                titleInput = (EditText) dialogView.findViewById(R.id.subject_title_);
                                titleInput.setSelection(titleInput.getText().length());
                                titleInput.setText(subject_title);
                                teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher);
                                teacherInput.setText(subject_content);
                                roomInput = (EditText) dialogView.findViewById(R.id.subject_room);
                                roomInput.setText(subject_attachment);

                                helper_main.showKeyboard(getActivity(), titleInput);

                                final ImageButton be = (ImageButton) dialogView
                                        .findViewById(R.id.imageButtonPri);
                                Subjects_helper.switchIcon(getActivity(), subject_icon, "subject_color", be);

                                be.setOnClickListener(new View.OnClickListener() {

                                    @Override
                                    public void onClick(View arg0) {

                                        ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                                                android.R.layout.select_dialog_item, android.R.id.text1,
                                                items) {
                                            @NonNull
                                            public View getView(int position, View convertView,
                                                    @NonNull ViewGroup parent) {
                                                //Use super class to create the View
                                                View v = super.getView(position, convertView, parent);
                                                TextView tv = (TextView) v.findViewById(android.R.id.text1);
                                                tv.setTextSize(18);
                                                tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon,
                                                        0, 0, 0);
                                                //Add margin between image and text (support various screen densities)
                                                int dp5 = (int) (24 * getActivity().getResources()
                                                        .getDisplayMetrics().density + 0.5f);
                                                tv.setCompoundDrawablePadding(dp5);

                                                return v;
                                            }
                                        };

                                        new android.app.AlertDialog.Builder(getActivity())
                                                .setPositiveButton(R.string.toast_cancel,
                                                        new DialogInterface.OnClickListener() {

                                                            public void onClick(DialogInterface dialog,
                                                                    int whichButton) {
                                                                dialog.cancel();
                                                            }
                                                        })
                                                .setAdapter(adapter, new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int item) {
                                                        if (item == 0) {
                                                            be.setImageResource(R.drawable.circle_red);
                                                            sharedPref.edit().putString("subject_color", "1")
                                                                    .apply();
                                                        } else if (item == 1) {
                                                            be.setImageResource(R.drawable.circle_pink);
                                                            sharedPref.edit().putString("subject_color", "2")
                                                                    .apply();
                                                        } else if (item == 2) {
                                                            be.setImageResource(R.drawable.circle_purple);
                                                            sharedPref.edit().putString("subject_color", "3")
                                                                    .apply();
                                                        } else if (item == 3) {
                                                            be.setImageResource(R.drawable.circle_blue);
                                                            sharedPref.edit().putString("subject_color", "4")
                                                                    .apply();
                                                        } else if (item == 4) {
                                                            be.setImageResource(R.drawable.circle_teal);
                                                            sharedPref.edit().putString("subject_color", "5")
                                                                    .apply();
                                                        } else if (item == 5) {
                                                            be.setImageResource(R.drawable.circle_green);
                                                            sharedPref.edit().putString("subject_color", "6")
                                                                    .apply();
                                                        } else if (item == 6) {
                                                            be.setImageResource(R.drawable.circle_lime);
                                                            sharedPref.edit().putString("subject_color", "7")
                                                                    .apply();
                                                        } else if (item == 7) {
                                                            be.setImageResource(R.drawable.circle_yellow);
                                                            sharedPref.edit().putString("subject_color", "8")
                                                                    .apply();
                                                        } else if (item == 8) {
                                                            be.setImageResource(R.drawable.circle_orange);
                                                            sharedPref.edit().putString("subject_color", "9")
                                                                    .apply();
                                                        } else if (item == 9) {
                                                            be.setImageResource(R.drawable.circle_brown);
                                                            sharedPref.edit().putString("subject_color", "10")
                                                                    .apply();
                                                        } else if (item == 10) {
                                                            be.setImageResource(R.drawable.circle_grey);
                                                            sharedPref.edit().putString("subject_color", "11")
                                                                    .apply();
                                                        }
                                                    }
                                                }).show();
                                    }
                                });

                                android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                                        getActivity());
                                builder.setTitle(R.string.subjects_edit);
                                builder.setView(dialogView);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                Subject_DbAdapter db = new Subject_DbAdapter(getActivity());
                                                db.open();

                                                String inputTitle = titleInput.getText().toString().trim();
                                                String inputTeacher = teacherInput.getText().toString().trim();
                                                String inputRoom = roomInput.getText().toString().trim();

                                                Date date = new Date();
                                                DateFormat dateFormat = new SimpleDateFormat(
                                                        "yy-MM-dd_HH-mm-ss", Locale.getDefault());
                                                String creation = dateFormat.format(date);

                                                if (db.isExist(creation)) {
                                                    Snackbar.make(titleInput,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    db.insert(inputTitle, inputTeacher,
                                                            sharedPref.getString("subject_color", creation),
                                                            inputRoom, helper_main.createDate());
                                                    dialog.dismiss();
                                                    setSubjectsList();
                                                }

                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.support.v7.app.AlertDialog dialog2 = builder.create();
                                dialog2.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {

                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setSubjectsList();
                                            }
                                        });
                                snackbar.show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:co.taqat.call.CallActivity.java

private void displayConferenceParticipant(int index, final LinphoneCall call) {
    LinearLayout confView = (LinearLayout) inflater.inflate(R.layout.conf_call_control_row, container, false);
    conferenceList.setId(index + 1);/*  w ww  . ja va2  s  .  com*/
    TextView contact = (TextView) confView.findViewById(R.id.contactNameOrNumber);

    LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(call.getRemoteAddress());
    if (lContact == null) {
        contact.setText(call.getRemoteAddress().getUserName());
    } else {
        contact.setText(lContact.getFullName());
    }

    registerCallDurationTimer(confView, call);

    ImageView quitConference = (ImageView) confView.findViewById(R.id.quitConference);
    quitConference.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            exitConference(call);
        }
    });
    conferenceList.addView(confView);

}