2017-01-29 4 views
0
私はクリッカブルtextviewsのリストを望むよ

のリストを作成するにはどのようにこれは私がはTextviews

クリック可能な項目のすべてのリストをご希望

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

    <TextView 
     android:id="@+id/marque_scrolling_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:padding="16dp" 
     android:scrollHorizontally="true" 
     android:singleLine="true" 
     android:text="Create a Marquee (Scrolling Text) in Android Using TextView. Android Marquee (Scrolling Text) Tutorial with Example" 
     android:textSize="24sp" /> 
</LinearLayout> 

を持っているxmlですこれは私が「コードですm:

TextView marque1 = (TextView) this.findViewById(R.id.marque_scrolling_text); 
marque1.setSelected(true); 

marque1.setOnClickListener(new View.OnClickListener() 
{ 
    @Override 
    public void onClick(View v) 
    { 
     System.out.println("dhgjgf jfgsfjhsgfsjfgdfjh"); 
    } 
}); 

これは可能ですか?

+0

アンドロイドのListViewウィジェットを使用https://developer.android.com/guide/topics/ui/layout/listview.html – USKMobility

+0

しかし、テキストの色を変更するのに苦労しているListview +でキャンバスマーキー。 –

+0

なぜマーキーをリストビューで使用できないのですか?そして、あなたはテキストの色を変えることでどんな問題を抱えていますか? –

答えて

0

ListViewを使用できない場合は、自分でTextViewを動的に作成して追加できます。

私はあなたがTextViewsとして表示する文字列の配列を持っていると仮定します、リストを反復その後

​​

作成:

String[] strings = {"TextA", "TextB"}; 

はすべてTextViewsが含まれますレイアウトを取得します。各文字列の新しいTextViewを追加し、onClickListenerを追加して(テキストの色を変更するなど)必要な操作を行い、レイアウトに追加します。

for(String s : strings) 
{ 
    TextView newTextView = new TextView(this); 
    newTextView.setText(s); 
    newTextView.setTextColor(#0066ff); // for example 
    newTextView.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick(View v) 
      { 
       System.out.println("dhgjgf jfgsfjhsgfsjfgdfjh"); 
      } 
     }); 

    layout.addView(newTextView); 
} 
関連する問題