1
How can I change the color of a listview when selecting?
below goes as is the stuck in my project:
listDebitosPendentes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent= new Intent(getApplicationContext(),DetalhesDebitosActivity.class);
//Passa para a activity o id no banco de dados
intent.putExtra("ID", id);
startActivity(intent);
}
});
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/color_list"
android:weightSum="1">
<EditText
android:layout_width="match_parent"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/edtPesquisa"
android:drawableLeft="@android:drawable/ic_search_category_default"
android:layout_marginTop="15dp"
android:hint="Pesquisa rápida"
tools:ignore="HardcodedText,NestedWeights,RtlHardcoded"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="45dp" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listDebitosPendentes"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
tools:ignore="NestedScrolling"
android:footerDividersEnabled="false"/>
</LinearLayout>
drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimary" android:state_pressed="true"/>
</selector>
You want it to change color when the item is "clicked"?
– Marco Giovanni
@Marcogiovanni, this, I want you to change when you click. and then go back to the pattern.
– rodrigo.oliveira
See if it fits you. Bug
listDebitosPendentes.setBackgroundColor(Color.BLUE);
within theonItemClick
.– Rodrigo Paixão
@Rodrigopaixão, that way no. Because he painted the whole list and she does not return to the pattern.
– rodrigo.oliveira