Ich versuche herauszufinden, warum mein Aufruf findViewById auf meinem Layout den generischen Typ "View" anstelle des Typs "ScrollView", dass die fragliche Ansicht deklariert wird zurückgegeben wie.Android: findViewById Rückgabetyp ist View anstelle von ScrollView
Wenn Sie unten sehen, listet meine XML-Datei die Ansicht mit der ID "scrollview" eindeutig als <ScrollView>
auf, aber findViewById für dieses Element gibt nur eine Ansicht zurück, keine ScrollView. Warum passiert dies?
Hinweis: der übergeordnete Container zu diesem XML-Layout ist ein Fragment, nicht sicher, ob dies Dinge ändert.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.menu_fragment_capo, container, false);
mScrollview = v.findViewById(R.id.scrollview); //ERROR HERE
mScrollview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//mScrollview.smoothScrollTo();
return true; //true = not scrollable
}
});
}
scroller_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/buttonLayoutParent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
Danke. Dies ist die Lösung. – Cody