Java tutorial
package com.android.projectz.teamrocket.thebusapp.adapters; /* Copyright (C) 2016-2017 TeamRocket This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ import android.app.Activity; import android.graphics.drawable.Drawable; import android.support.v4.graphics.drawable.DrawableCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import com.android.projectz.teamrocket.thebusapp.R; import com.android.projectz.teamrocket.thebusapp.settings.SettingGeneralActivity; import com.android.projectz.teamrocket.thebusapp.util.SharedPreferencesUtils; /** * CustomListSetting: * questa classe permette una customizzazione della classica lista offerta da android * attraverso delle modifiche alla classe adapter. * <p> * Created by simone98dm on 08/12/16. */ public class CustomListSettingOther extends ArrayAdapter<String> { private final Activity context; private final String[] text; private final Drawable[] imageId; private final String[] subtext; /** * costruttore con i parametri necessari * * @param context * @param text * @param subtext * @param imageId */ public CustomListSettingOther(Activity context, String[] text, String[] subtext, Drawable[] imageId) { super(context, R.layout.list_setting, text); this.context = context; this.text = text; this.subtext = subtext; this.imageId = imageId; } /** * adattatore custom per la visualizzazione della lista * 1. titolo * 2. sottotitolo * 3. immagine * * @param position * @param view * @param parent * @return */ @Override public View getView(int position, View view, ViewGroup parent) { LayoutInflater inflater = context.getLayoutInflater(); View rowView = inflater.inflate(R.layout.list_setting, null, true); TextView txtTitle = (TextView) rowView.findViewById(R.id.txt); TextView txtSubtitle = (TextView) rowView.findViewById(R.id.subtxt); ImageView imageView = (ImageView) rowView.findViewById(R.id.img); Drawable colorImg = null; if (SharedPreferencesUtils.getSelectedTheme(context).equals("AppTheme")) { colorImg = changeColorOfIcons(imageId[position], R.color.iconLight); } else { colorImg = changeColorOfIcons(imageId[position], R.color.iconDark); } txtTitle.setText(text[position]); txtSubtitle.setText(subtext[position]); imageView.setImageDrawable(colorImg); return rowView; } public Drawable changeColorOfIcons(Drawable image, int color) { image = DrawableCompat.wrap(image); DrawableCompat.setTint(image, context.getResources().getColor(color)); return image; } }