Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

android - How set ListView not clickable

I have this ListView that just needs to show data.
So I don't want to make it clickable.
First I've tried changing XML listview to:

<ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:clickable="false" >

But it didn't work.
So to solve my problem I set through code:

  list.setSelector(android.R.color.transparent); 

but I can't believe there's no better solution. Any idea?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here it is, following the comment:

One way to do so is: ListView.setOnClickListener(null); OR

You can add android:focusable="false" android:focusableInTouchMode="false" OR

another way in the layout android:listSelector="@android:color/transparent"

Cheers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...