2016-05-06 7 views
0

リサイクラビューの1つの要素にフローティングテキストビューを追加するにはどうすればよいですか?

<android.support.v7.widget.RecyclerView 
    android:id="@+id/drawerList" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/nav_header_container" 
    android:layout_marginTop="15dp" /> 

私はこの文字列配列をRecyclerViewでデータを表示するために使用され、この

<string-array name="my_array"> 
    <item>@string/item_1</item> 
    <!--<item>@string/item_2</item>--> 
    <item>@string/item_3</item> 
    <item>@string/item_4</item> 
    <item>@string/item_5</item> 
    <item>@string/item_6</item> 

ような文字配列を有するが、以下のようにIはRecyclerViewを有します。私はitem_4と一緒にテキストビューを表示したい、それは可能ですか?それを作る方法?

+1

問題を適切に記述してください。 –

+0

解決しましたか? –

答えて

0

あなたのonBindViewHolderメソッドでは、表示する要素のチェックを入れて、それに何をしたいのかをしっかりと設定します。 RecyclerViewアダプタに活動峠から

1

このリスト

try { 
     String[] array = getApplicationContext().getResources().getStringArray(R.array.my_array); 
     List<String> list = new ArrayList<String>(); 
     list = Arrays.asList(array); 

     //pass this list to RecyclerView adapter 

    }catch (Exception e){e.printStackTrace();} 
0

いくつかの解決策:

1.-あなたはonBindViewHolderで位置を確認するときは、第四項目に文字列をCONCATすることができます。

2.レイアウトを作成して、onCreateViewHolderに展開することができます。このレイアウトには、項目のテキストビューとその横に表示されるテキストの2つのtextViewがあります。 2番目のテキストビューを表示する必要があることが検出されると、テキストビューの内容と可視性が変更されます。

<LinearLayout android:orientation="horizontal" 
xmlns:android="http://schemas.android.com/apk/res/android" > 

<TextView 
    android:id="@+id/items" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/textViewNextToItemOfChoice" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:visibility="gone" /> 
</LinearLayout> 

次にコードでは、textview "textViewNextToItemOfChoice"の可視性とその内容を変更するだけです。

リストを作成するために文字列の配列を使うのではなく、オブジェクトを作成する必要があると思います。このようにして、2つの文字列を持つオブジェクトを作成することができます。また、両方の文字列が表示されているかどうかを確認するときに、アダプタでアダプタを表示できます。

関連する問題