をリストビューを使用することができます。
<?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);
}
応答のためのThx。特定のtextviewをクリックすると、A、B、C ...の文字を印刷する必要があります。どうやってするか? – user1222905
私は自分の質問を編集しました。 a1は文字Aに対応するテキストビューです – user1222905
あなたはそれらを印刷する必要がありますか?あなたはトーストのような意味ですか?またはあなたはそれらを何らかのオブジェクトに書き込む必要がありますか? – MikeIsrael