Nimrod Shai
Nimrod Shai

Reputation: 1179

Cant change View background colour programmatically

Im an android newbie so please forgive me...

This is my code:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;

    if (convertView == null) {
        viewHolder = new ViewHolder();
        convertView = LayoutInflater.from(context).inflate(R.layout.adapter_who_row, null);
        viewHolder.nameTextView = (TextView) convertView.findViewById(R.id.text);
        viewHolder.companyTextView = (TextView) convertView.findViewById(R.id.whoRowCompany);
        viewHolder.dotView = convertView.findViewById(R.id.whoRowDot);

        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    String textToShow = dataArray.get(position);
    viewHolder.nameTextView.setText(textToShow);
    viewHolder.dotView.setBackgroundColor(getResources().getColor(R.color.red));
    viewHolder.companyTextView.setText("Test");

    return convertView;
}


class ViewHolder {
    TextView nameTextView;
    TextView companyTextView;
    View dotView;
}

dotView doesn't change its colour... However, the two textVies does change their text.

What could it be?


Edit: The xml is holding two editTexts and one View.

Below is my xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:layout_centerVertical="true">


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.85"
            android:layout_gravity="center"
            android:gravity="center">

            <View
                android:id="@+id/whoRowDot"
                android:layout_width="40px"
                android:layout_height="40px"
                android:backgroundTint="@color/noteColor">

            </View>
            <!--android:background="@drawable/round_button"-->


        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            android:background="@color/clear"
            android:layout_weight="0.15">

            <TextView
                android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="0dp"
                android:text="User Name"
                android:fontFamily="Roboto-Light"
                android:background="@color/clear"/>

            <TextView
                android:id="@+id/whoRowCompany"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="15dp"
                android:text="Company"
                android:textColor="@color/lightGrey"
                android:background="@color/clear"/>

        </LinearLayout>


    </LinearLayout>


</LinearLayout>

Thanks

Upvotes: 0

Views: 900

Answers (1)

KR_Android
KR_Android

Reputation: 1159

remove this line from your xml view and try:

android:backgroundTint="@color/noteColor"

Upvotes: 1

Related Questions