2012-04-02 3 views
0

私はすべてのtextViewsオーバーfastscrollが必要main.xmlアルファベットのtextviewsに高速スクロールを作成し、最初の文字を印刷する方法は?

<LinearLayout... 
> 
<textview adndroid:tag="A"> 
... 
till to Z. 
</LinearLayout> 

で複数のtextviewsを持っています。どうやってするか?助けが要る。

AまたはBを押すと文字を印刷する必要があります。どうやってするか?あなたが行うことができますlink

答えて

0

:ここ

a1.setOnTouchListener(newOnTouchListener(){ 
public boolean onTouch(View w,MotionEvent event) 
{ 
//? WHAT TO WRITE HERE? 
I NEED TO PRINT ON THE SCREEN A because I CLICK ON A TEXTVIEW. 
I LIKE TO PRINT THE CHARACTER A IN A BOX (like the one from contact list android) 

} 

}); 

は、サンプルコードは、あなたの質問の後半部分については

<ScrollView android:id="@+id/ScrollView02" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

<LinearLayout 
    .... 
> 
<textview ...yourtextview > 
... 
</LinearLayout> 

</ScrollView> 

、私はあなたがすべてのあなたのtextViewsにandroid:clickable="true"を追加し、処理するために持っていると思いますそれはコードで。

そうしないと、XMLで文字のレイアウトを指定して最初に...それは簡単です、このように、setOnItemClickListener(new OnItemClickListener()

+0

応答のためのThx。特定のtextviewをクリックすると、A、B、C ...の文字を印刷する必要があります。どうやってするか? – user1222905

+0

私は自分の質問を編集しました。 a1は文字Aに対応するテキストビューです – user1222905

+0

あなたはそれらを印刷する必要がありますか?あなたはトーストのような意味ですか?またはあなたはそれらを何らかのオブジェクトに書き込む必要がありますか? – MikeIsrael

0

をリストビューを使用することができます。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="?attr/actionBarSize" 
    > 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/list_products" 
     android:fastScrollEnabled="true" 
     /> 

    <LinearLayout 
     android:orientation="vertical" 
     android:id="@+id/chars_layout" 
     android:layout_width="26dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:layout_alignParentEnd="true" 
     > 

    </LinearLayout> 


</RelativeLayout> 

その後コードであなたに文字を追加しますレイアウト:

 private void addCharsForScrolling(LinearLayout charsLayout, ArrayList<String> sectionList) { 
      Collections.sort(sectionList); 
      sections = new String[sectionList.size()]; 

      for (int m = 0; m < sectionList.size(); m++) { 
       sections[m] = sectionList.get(m); 
         addScrollText(charsLayout, sectionList.get(m),false); 

      } 
     } 

ここではsectionlistのコードです:

private void findChars (ArrayList<BrandsRestaurantsModel> brands, ArrayList <ProductLists.ResourantsWithPlace> imgstructure){ 
     LinearLayout charsLayout = (LinearLayout) this.rootview.findViewById(R.id.chars_layout); 

      mapIndex = new LinkedHashMap<String, Integer>(); 
      sectionList = new ArrayList<String>(); 
      for (int x = 0; x < brands.size(); x++) { 
       sectionList.add(brands.get(x).getCh()); 
       if (!mapIndex.containsKey(brands.get(x).getCh())) 
        mapIndex.put(brands.get(x).getCh(), x); 
      } 
      Set<String> sectionLetters = mapIndex.keySet(); 
      ArrayList<String> sectionList = new ArrayList<String>(sectionLetters); 
      addCharsForScrolling(charsLayout, sectionList); 

    } 
関連する問題