Привет, я новичок в разработке Android! Я изучаю его самостоятельно, у меня есть сетка с несколькими текстовыми представлениями внутри него. Я хочу изменить цвет текста текстового вида, на который я нажимаю! Текстовый вид должен изменить свой цвет, на который я нажимаю.GridView Сохранить TextColor по щелчку
Я делаю это нравится: Это мой GridView Пункт XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="2dp"
android:paddingTop="2dp">
<TextView
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="@drawable/bg_tv_categories"
android:ellipsize="end"
android:gravity="center"
android:lines="1"
android:padding="2dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/text_pressed"
android:textSize="15sp"></TextView>
</RelativeLayout>
Мой Selector XML является:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/blue"/>
<item android:color="@android:color/holo_red_light"/>
</selector>
Адаптер:
private static final class GridAdapter extends BaseAdapter {
final ArrayList<CategoryModel> mItems;
final int mCount;
final Context ctx;
TextView text = null;
View view;
/**
* Default constructor
*
* @param items to fill data to
*/
private GridAdapter(final ArrayList<CategoryModel> items, Context ctx) {
mCount = items.size();
//mItems = new ArrayList<String>();
mItems = items;
this.ctx=ctx;
}
@Override
public int getCount() {
return mCount;
}
@Override
public Object getItem(final int position) {
return mItems.get(position);
}
@Override
public long getItemId(final int position) {
return position;
}
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
view = convertView;
if (view == null) {
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gridview_item, parent, false);
text = (TextView) view.findViewById(R.id.item);
}
final CategoryModel myItem = mItems.get(position);
if (text != null)
text.setText(myItem.name);
//text.setText(mItems.get(position));
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//text.setBackgroundColor(ctx.getResources().getColor(R.color.color_77));
categories = myItem.id;
//Toast.makeText(parent.getContext(), "" + myItem.id, Toast.LENGTH_SHORT).show();
}
});
return view;
}
}
}
Это делает изменения цвет текста, но только когда я нажимаю его, я имею в виду, что хочу сохранить синий цвет текстового вида t вн, на котором я нажимаю на,
Заранее спасибо
пожалуйста, поделитесь код адаптера –
обновил мой вопрос, пожалуйста, проверьте адаптер код –
Не ясно, что вы ищете? Можете ли вы поделиться снимками экрана с ожидаемым выходом и каков текущий вывод? – Rachit