我在main.xml中有多个textview
<LinearLayout...
>
<textview adndroid:tag="A">
...
till to Z.
</LinearLayout>
我需要对所有textViews进行快速滚动。怎么做?需要一些帮助。
按A或B时我必须打印字符,依此类推。怎么做?
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)
}
});
以下是一个示例代码:link
答案 0 :(得分:0)
你可以这样做:
<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>
对于问题的第二部分,我认为您必须在所有textView中添加android:clickable="true"
并使用代码处理它。
否则,您可以使用带有setOnItemClickListener(new OnItemClickListener()
的ListView,这样就更容易......
答案 1 :(得分:0)
首先在xml:
中指定字符的布局<?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);
}