2012-04-11 40 views
1

我有一个片段中的元素列表。 我想禁用列表的标题列表视图第一个元素不可点击

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

这里的代码我的名单的细胞:

<?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> 

我试图让机器人:点击= FALSE或Android:可聚焦=”假“,它不起作用。

+0

列表视图中第一个元素没有点击,但我无法看到任何列表视图 – vipin 2012-04-11 09:46:15

+0

所以你试图让第一元素n列表视图不可点击,其余可点击? – Katana24 2012-04-11 09:50:05

+0

Vipin:它是单元格的xml(列表中的一个元素) Katana:是的,我希望指示“收藏夹”被禁用的第一个元素,比指示以A开始的字母元素“A”被禁用到 – 2012-04-11 10:27:18

回答

0

得到了它,我在我的cell.xml

因此,每次添加单元格时都会绘制文本。 我们必须在主XML声明这一点,比文本从我们的适配器改变:

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

的一种方法,使某些ListView项不可点击的是:

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... 
     } 

    } 
}); 

另一种方法是修改自定义适配器:

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... 
     } 
    } 

}); 
+0

我试过这个:if(position == 0){ v.setClickable(false); ,它不工作! – 2012-04-11 10:30:46

+0

你还试过第一种方法吗? – hendrix 2012-04-11 11:58:43