haythem souissi
haythem souissi

Reputation: 3273

List view first element no clickable

I have a list of element in a fragment. I want to disable the title of list

http://bugs.haploid.fr/file_download.php?file_id=856&type=bug

here are the code the cell of my list:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/stations_listView_layout">
    <com.infrabel.railtime.views.RobotoMediumTextView
        android:id="@+id/header_textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="10dip"
        android:paddingBottom="5dip"
        android:layout_marginTop="29dip"
        android:text="A"
        style="@style/FragmentTitleSecondary">
    </com.infrabel.railtime.views.RobotoMediumTextView>

    <View
        android:id="@+id/header_bar"
        android:layout_width="match_parent"
        android:layout_height="2dip"
        android:background="@color/fragment_title_color">
    </View>

    <RelativeLayout
        style="@style/stations_listView_inner_layout"
        android:layout_width="fill_parent"
        android:layout_height="60dip">

        <com.infrabel.railtime.views.RobotoMediumTextView
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="30dip"
            android:layout_gravity="center_vertical"
            android:textSize="@dimen/menu_list_item_primary_text_size"
            android:textColor="@color/grey_normal">
        </com.infrabel.railtime.views.RobotoMediumTextView>

        <com.infrabel.railtime.views.RobotoMediumTextView
            android:id="@+id/details"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="25dip"
            android:textSize="@dimen/fragment_title_text_size"
            android:textColor="@color/grey_light">
        </com.infrabel.railtime.views.RobotoMediumTextView>
    </RelativeLayout>
</LinearLayout>

i tried to set android:clickable = false or android:focusable="false" and it doesn't work.

Upvotes: 1

Views: 1260

Answers (2)

haythem souissi
haythem souissi

Reputation: 3273

got it , i have in my cell.xml

so the text will be drawn every time when i add cell. we must declare this in the main xml, than change the text from our adapter:

String firstLetter = station.getTitle().substring(0, 1);
if (position == _alphaIndexer.get(firstLetter)) {
    TextView header = (TextView) activity.findViewById(R.id.header_textview);
    header.setText(firstLetter);
}

Upvotes: 0

matejs
matejs

Reputation: 3536

One way to make certain ListView item not clickable is:

list.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
        if(position == 0) {
                    // FIRST ITEM - DO NOTHING
        } else {
                    // DO SOMETHING IF YOU WISH...
        }

    }
});

another way would be to modify your custom adapter:

list.setAdapter(new ArrayAdapter<String>(this, R.layout.item,
        listItems) {

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final TextView v = (TextView) super.getView(position,
                convertView, parent);
        if(position == 0) {
                v.setClickable(false);
                // havent tested this thou...
        }
    }

});

Upvotes: 1

Related Questions