Example usage for android.view View setTag

List of usage examples for android.view View setTag

Introduction

In this page you can find the example usage for android.view View setTag.

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:com.aniruddhc.acemusic.player.BlacklistManagerActivity.BlacklistedArtistsMultiselectAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Cursor c = (Cursor) getItem(position);
    SongsListViewHolder holder = null;//  ww w .  j ava  2s.co m

    if (convertView == null) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_artists_layout,
                parent, false);
        holder = new SongsListViewHolder();
        holder.image = (ImageView) convertView.findViewById(R.id.artistThumbnailMusicLibraryEditor);
        holder.title = (TextView) convertView.findViewById(R.id.artistNameMusicLibraryEditor);
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.artistCheckboxMusicLibraryEditor);

        convertView.setTag(holder);
    } else {
        holder = (SongsListViewHolder) convertView.getTag();
    }

    final View finalConvertView = convertView;
    final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID));
    final String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST));
    final String songBlacklistStatus = c.getString(c.getColumnIndex(DBAccessHelper.BLACKLIST_STATUS));
    String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH));

    holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

    //Set the song title.
    holder.title.setText(songArtist);
    mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image,
            BlacklistManagerActivity.displayImageOptions);

    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    try {
        if (BlacklistManagerActivity.songIdBlacklistStatusPair.get(songId).equals("TRUE")) {
            holder.checkBox.setChecked(true);
            convertView.setBackgroundColor(0xCCFF4444);
        } else {
            holder.checkBox.setChecked(false);
            convertView.setBackgroundColor(0x00000000);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    //Set a tag to the row that will attach the artist's name to it.
    convertView.setTag(R.string.artist, songArtist);

    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) {

            if (isChecked == true) {

                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCCFF4444);
                    AsyncBlacklistArtistTask task = new AsyncBlacklistArtistTask(songArtist);
                    task.execute(new String[] { "ADD" });
                }

            } else if (isChecked == false) {

                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0x00000000);
                    AsyncBlacklistArtistTask task = new AsyncBlacklistArtistTask(songArtist);
                    task.execute(new String[] { "REMOVE" });

                }

            }

        }

    });

    return convertView;
}

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

public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        view = new ImageView(parent.getContext());
        view.setPadding(6, 2, 6, 2);/*from   w ww  .  j av a  2  s.c  om*/
        //view.getBackground().setColorFilter(Color.parseColor("#00ff00"), PorterDuff.Mode.DARKEN);
        view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.Color_1));

        view.invalidate();
    }

    int width = parent.getContext().getResources().getDisplayMetrics().widthPixels;
    if (URLS[position] != null) {
        Picasso.with(parent.getContext()).load(URLS[position]).noFade().resize(width / 4, width / 4)
                .centerCrop().error(R.drawable.no_image).placeholder(R.drawable.loading_image)
                .into((ImageView) view);
    }

    view.setTag(position);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                int pos = (int) v.getTag();
                zoomImageFromThumb(v, pos);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    return view;
}

From source file:com.housekeeper.activity.view.MediaImagePagerAdapter.java

@Override
public View getView(final int position, View view, ViewGroup container) {
    ViewHolder holder;/*from  w  w  w  . j a va2 s  .  c  om*/
    if (view == null) {
        holder = new ViewHolder();
        view = holder.imageView = new NetworkImageView(context);

        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LinkArticle media = imageURLList.get(getPosition(position));

                if (!StringUtils.isBlank(media.getLink())) {
                    Intent intent = new Intent(context, ShowWebViewActivity.class);
                    intent.putExtra("title", media.getTitle());
                    intent.putExtra("url", media.getLink());
                    context.startActivity(intent);
                }
            }
        });

        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    holder.imageView.setScaleType(ScaleType.CENTER_CROP);
    holder.imageView.setImageUrl(Constants.HOST_IP + imageURLList.get(getPosition(position)).getImgUrl(),
            ImageCacheManager.getInstance().getImageLoader());
    return view;
}

From source file:cc.softwarefactory.lokki.android.fragments.AddContactsFragment.java

private void setListAdapter() {

    adapter = new ArrayAdapter<String>(getActivity(), R.layout.add_people_row_layout, contactList) {

        @Override/*from  w w w.  j a  va 2 s  .c  o m*/
        public View getView(final int position, View convertView, ViewGroup parent) {

            ViewHolder holder;

            if (convertView == null) {
                convertView = getActivity().getLayoutInflater().inflate(R.layout.add_people_row_layout, parent,
                        false);
                holder = new ViewHolder();
                holder.name = (TextView) convertView.findViewById(R.id.contact_name);
                holder.email = (TextView) convertView.findViewById(R.id.contact_email);
                holder.photo = (ImageView) convertView.findViewById(R.id.contact_photo);
                convertView.setTag(holder);

            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            try {
                AQuery aq = new AQuery(convertView);
                String contactName = getItem(position);
                final String email = MainApplication.mapping.getString(contactName);

                avatarLoader.load(email, holder.photo);

                aq.id(holder.name).text(contactName);
                aq.id(holder.email).text(email);
                holder.position = position;

                convertView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        final Context context = getContext();
                        String title = context.getResources().getString(R.string.add_contact);
                        String message = context.getResources().getString(R.string.add_contact_dialog_save,
                                email);
                        new AlertDialog.Builder(context).setTitle(title).setMessage(message)
                                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        try {
                                            ServerApi.allowPeople(context, email);
                                            contactList.remove(position);
                                            notifyDataSetChanged();
                                            Toast.makeText(context, R.string.contact_added, Toast.LENGTH_SHORT)
                                                    .show();
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }).setNegativeButton(R.string.cancel, null).show();
                    }
                });

            } catch (JSONException e) {
                Log.e(TAG, e.getMessage());
            }
            return convertView;
        }
    };

    aq.id(R.id.add_contacts_list_view).adapter(adapter);
}

From source file:com.lsjwzh.widget.recyclerviewpagerdeomo.ViewPagerFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final Activity activity = getActivity();

    mToast = Toast.makeText(activity, "", Toast.LENGTH_SHORT);
    mToast.setGravity(Gravity.CENTER, 0, 0);

    mViewPager = (ViewPager) view.findViewById(R.id.list);
    mViewPager.setAdapter(new PagerAdapter() {
        @Override/*w w w.j  a  v a 2s.c om*/
        public int getCount() {
            return 100;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            final View view = LayoutInflater.from(getActivity()).inflate(R.layout.item, container, false);
            ((TextView) view.findViewById(R.id.title)).setText(position + "");
            view.setTag("" + position);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            if (object != null && object instanceof View) {
                container.removeView((View) object);
            }
        }

        @Override
        public int getItemPosition(Object object) {
            if (object instanceof View) {
                return Integer.valueOf(((View) object).getTag().toString());
            }
            return super.getItemPosition(object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }
    });
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {
            updateState(state);
        }
    });

    mStateText = (TextView) view.getRootView().findViewById(R.id.state);
    updateState(RecyclerView.SCROLL_STATE_IDLE);
}

From source file:com.aniruddhc.acemusic.player.MusicLibraryEditorActivity.MusicLibraryEditorSongsMultiselectAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Cursor c = (Cursor) getItem(position);
    SongsListViewHolder holder = null;/*  w w  w  . j a v  a2 s.  c  o  m*/

    if (convertView == null) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_songs_layout, parent,
                false);
        holder = new SongsListViewHolder();
        holder.image = (ImageView) convertView.findViewById(R.id.songThumbnailMusicLibraryEditor);
        holder.title = (TextView) convertView.findViewById(R.id.songNameMusicLibraryEditor);
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.songCheckboxMusicLibraryEditor);
        holder.subText = (TextView) convertView.findViewById(R.id.artistNameSongListView);

        convertView.setTag(holder);
    } else {
        holder = (SongsListViewHolder) convertView.getTag();
    }

    final View finalConvertView = convertView;
    final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID));
    final String songTitle = c.getString(c.getColumnIndex(DBAccessHelper.SONG_TITLE));
    String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH));
    String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST));

    holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

    holder.subText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.subText
            .setPaintFlags(holder.subText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

    //Set the songID as the view's tag.
    convertView.setTag(R.string.song_id, songId);

    //Set the song title.
    holder.title.setText(songTitle);
    holder.subText.setText(songArtist);
    mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image,
            MusicLibraryEditorActivity.displayImageOptions);

    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    if (MusicLibraryEditorActivity.songDBIdsList.contains(songId)) {
        convertView.setBackgroundColor(0xCC0099CC);
        holder.checkBox.setChecked(true);
    } else {
        convertView.setBackgroundColor(0x00000000);
        holder.checkBox.setChecked(false);
    }

    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) {

            if (isChecked == true) {

                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCC0099CC);
                    MusicLibraryEditorActivity.songDBIdsList.add(songId);
                }

            } else if (isChecked == false) {

                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCC0099CC);
                    MusicLibraryEditorActivity.songDBIdsList.remove(songId);
                }

            }

        }

    });

    return convertView;
}

From source file:com.aniruddhc.acemusic.player.PlaylistEditorActivity.PlaylistEditorSongsMultiselectAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Cursor c = (Cursor) getItem(position);
    SongsListViewHolder holder = null;//from  w  w  w .j  a  v a2 s .  c  o  m

    if (convertView == null) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_songs_layout, parent,
                false);
        holder = new SongsListViewHolder();
        holder.image = (ImageView) convertView.findViewById(R.id.songThumbnailMusicLibraryEditor);
        holder.title = (TextView) convertView.findViewById(R.id.songNameMusicLibraryEditor);
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.songCheckboxMusicLibraryEditor);
        holder.subText = (TextView) convertView.findViewById(R.id.artistNameSongListView);

        convertView.setTag(holder);
    } else {
        holder = (SongsListViewHolder) convertView.getTag();
    }

    final View finalConvertView = convertView;
    final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID));
    final String songTitle = c.getString(c.getColumnIndex(DBAccessHelper.SONG_TITLE));
    String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH));
    String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST));

    holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

    holder.subText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.subText
            .setPaintFlags(holder.subText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

    //Set the songID as the view's tag.
    convertView.setTag(R.string.song_id, songId);

    //Set the song title.
    holder.title.setText(songTitle);
    holder.subText.setText(songArtist);
    mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image,
            PlaylistEditorActivity.displayImageOptions);

    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    if (PlaylistEditorActivity.songDBIdsList.contains(songId)) {
        convertView.setBackgroundColor(0xCC0099CC);
        holder.checkBox.setChecked(true);
    } else {
        convertView.setBackgroundColor(0x00000000);
        holder.checkBox.setChecked(false);
    }

    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) {

            if (isChecked == true) {

                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCC0099CC);
                    PlaylistEditorActivity.songDBIdsList.add(songId);
                }

            } else if (isChecked == false) {

                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCC0099CC);
                    PlaylistEditorActivity.songDBIdsList.remove(songId);
                }

            }

        }

    });

    return convertView;
}

From source file:com.aniruddhc.acemusic.player.BlacklistManagerActivity.BlacklistedSongsMultiselectAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Cursor c = (Cursor) getItem(position);
    SongsListViewHolder holder = null;/*  w w  w.  j  a  v a2s .c om*/

    if (convertView == null) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_songs_layout, parent,
                false);
        holder = new SongsListViewHolder();
        holder.image = (ImageView) convertView.findViewById(R.id.songThumbnailMusicLibraryEditor);
        holder.title = (TextView) convertView.findViewById(R.id.songNameMusicLibraryEditor);
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.songCheckboxMusicLibraryEditor);
        holder.subText = (TextView) convertView.findViewById(R.id.artistNameSongListView);

        convertView.setTag(holder);
    } else {
        holder = (SongsListViewHolder) convertView.getTag();
    }

    final View finalConvertView = convertView;
    final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID));
    final String songTitle = c.getString(c.getColumnIndex(DBAccessHelper.SONG_TITLE));
    final String songFilePath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_FILE_PATH));
    String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH));
    String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST));
    String songBlacklistStatus = c.getString(c.getColumnIndex(DBAccessHelper.BLACKLIST_STATUS));

    holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

    holder.subText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.subText
            .setPaintFlags(holder.subText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

    //Set the songID as the view's tag.
    convertView.setTag(R.string.song_id, songId);
    convertView.setTag(R.string.song_file_path, songFilePath);

    //Set the song title.
    holder.title.setText(songTitle);
    holder.subText.setText(songArtist);
    mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image,
            BlacklistManagerActivity.displayImageOptions);

    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    if (BlacklistManagerActivity.songIdBlacklistStatusPair.get(songId).equals("TRUE")) {
        convertView.setBackgroundColor(0xCCFF4444);
        holder.checkBox.setChecked(true);
    } else {
        convertView.setBackgroundColor(0x00000000);
        holder.checkBox.setChecked(false);
    }

    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) {

            if (isChecked == true) {

                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCCFF4444);
                    BlacklistManagerActivity.songIdBlacklistStatusPair.put(songId, true);
                }

            } else if (isChecked == false) {

                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0x000000);
                    BlacklistManagerActivity.songIdBlacklistStatusPair.put(songId, false);
                }

            }

        }

    });

    return convertView;
}

From source file:com.notalenthack.blaster.CommandListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // get already available view or create new if necessary
    FieldReferences fields;/*from www . ja  va 2 s. c o  m*/
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.command_item, null);
        fields = new FieldReferences();
        fields.commandStart = (TextView) convertView.findViewById(R.id.commandLine);
        fields.commandName = (TextView) convertView.findViewById(R.id.commandName);
        fields.cpuUsage = (TextView) convertView.findViewById(R.id.cpuUsage);
        fields.playButton = (ImageButton) convertView.findViewById(R.id.btnCommandAction);
        fields.imageView = (ImageView) convertView.findViewById(R.id.btnEditCommand);

        convertView.setTag(fields);
    } else {
        fields = (FieldReferences) convertView.getTag();
    }

    // set proper values into the view
    Command command = mCommands.get(position);
    String name = command.getName();
    String cmdStart = command.getCommandStart();
    int cpuUsage = command.getCpuUsage();

    if (name == null || name.length() <= 0)
        name = "Unknown";

    fields.imageView.setImageResource(command.getResourceId());
    fields.commandName.setText(name);
    fields.commandStart.setText(cmdStart);
    if (command.getDisplayStatus()) {
        StringBuffer buffer = new StringBuffer("Cpu ");
        buffer.append(Integer.toString(cpuUsage));
        buffer.append("%");
        fields.cpuUsage.setText(buffer.toString());
    } else {
        fields.cpuUsage.setText("");
    }

    // only allow edit & delete on non-system command item
    if (!command.isSystemCommand()) {
        fields.imageView.setBackground(mActivity.getResources().getDrawable(R.drawable.transparent_button));
        fields.imageView.setOnClickListener(mActivity);
    }
    fields.imageView.setTag(new Integer(position));
    if (command.getCommandStart().equalsIgnoreCase(Command.OBEX_FTP_START)) {
        fields.playButton.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.ic_file));
    } else {
        if (command.getStatus() == Command.Status.NOT_RUNNING) {
            fields.playButton.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.ic_action_play));
        } else {
            fields.playButton.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.ic_action_stop));
        }
    }

    fields.playButton.setOnClickListener(mActivity);
    fields.playButton.setTag(new Integer(position));

    return convertView;
}

From source file:com.sahildave.snackbar.SnackBar.java

private void addSingleLineInfo(String message, String subMessage, MessageType messageType) {
    View v = activity.getLayoutInflater().inflate(R.layout.usb_singleline_info, null);
    TextView mSnackMsgView = (TextView) v.findViewById(R.id.snackMessage);
    TextView mSnackSubMsgView = (TextView) v.findViewById(R.id.snackSubMessage);
    ImageView mSnackIcon = (ImageView) v.findViewById(R.id.snackIcon);

    mSnackMsgView.setText(message);/*from ww w . j a  v a2s . com*/
    mSnackSubMsgView.setText(subMessage);
    setSnackIcon(messageType, mSnackIcon);

    v.setTag(messageType);
    addToView(v);
}