Выделите элемент TextView в списке - PullRequest
2 голосов
/ 01 июня 2011

У меня есть ListView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:orientation="vertical">

    <ImageView 
        android:layout_height="wrap_content"
        android:id="@+id/imageView1"
        android:src="@drawable/tab"
        android:layout_gravity="center_horizontal"
        android:layout_width="fill_parent"></ImageView>

    <TextView
        android:id="@+id/subcat"
        android:background="#b9cd4a"
        android:layout_width="fill_parent"
        android:textColor="#fff"
        android:textStyle="bold"
        android:layout_height="35dp"
        android:textSize="18dp"
        android:paddingLeft="10dp"
        android:paddingTop="6dp"
        android:text="Choose Location"></TextView>

    <ListView
        android:id="@+id/sub_catlist"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:listSelector="@color/black"></ListView>

</LinearLayout>

И я раздуваю список, используя макет TextView:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="#fff"
    android:orientation="vertical"
    android:layout_height="65dp" >

    <TextView
        android:text="@+id/albumDetails"
        android:id="@+id/albumDetails"
        android:textColor="#000"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:textSize="16dp"
        android:layout_width="wrap_content"
        android:paddingTop="8dp"
        android:layout_height="45dp"></TextView>

</LinearLayout>

Проблема в том, что когда я нажимаю элемент списка, я не вижу ничегоизюминка.Мне нужно показать основной момент, когда пользователь нажимает элемент.Как я могу это сделать?

Ответы [ 3 ]

2 голосов
/ 01 июня 2011

TextView - это событие перехвата клика от ListView. Установить атрибуты

android:focusable="false"
android:clickable="false" 

к списку TextView.

0 голосов
/ 01 июня 2011

В пользовательском списке ниже используется код.

 TextViewClick.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {

                    int count = listview.getChildCount();
                    for (int i = 0; i < count; i++) {
                        View v = listview.getChildAt(i);
                        TextView tx = (TextView) v.findViewById(R.id.txt1);
                        txt1.setBackgroundColor(Color.RED);
                    }
                    txt1.setBackgroundColor(Color.GREEN);
            }
 });

0 голосов
/ 01 июня 2011

Я думаю, что проблема может быть в android:listSelector="@color/black", удалите эту строку

Пример ListView

<ListView
    android:id="@+id/nativecontacts_contacts_ListView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:drawSelectorOnTop="false"
    android:background="@color/White"
    android:divider="@drawable/menu_line"
    android:cacheColorHint="#00000000"
    android:clickable="true" />
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...