I cannot set the position of my Horizontal ScrollView in my main.xml because I am unable to target it using the code below. This method has always worked for me when targeting TextViews or Buttons, so i'm not sure why a ScrollView should be treated differently.
ScrollView scrollview1 = (ScrollView)findViewById(R.id.scrollview1);
So far I've been unable to find a working example of someone doing something similar that I could implement into my code successfully to scroll my bar to where it needs to be.
Here is what my error log displays during the app crash
dalvikvm threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
AndroidRuntime FATAL EXCEPTION: main
AndroidRuntime java.land.ClassCastException: android.widget.HorizontalScrollView cannot be cast to android.widget.ScrollView
AndroidRuntime at com.testButtons.TestButtonsActivity.onKeyDown(TestButtonsActivity.java)
Here is the code block that holds the troubled code.
I'm using the android return key to exit a menu and go back to main.xml with horizontal scrollview1 set 40dp from the left.
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
if(pageNum < 4){
setContentView(R.layout.main);
ScrollView scrollview1 = (ScrollView)findViewById(R.id.scrollview1);
//scrollview1.scrollTo(40,0);
}else if(pageNum >= 4 && pageNum < 20){
setContentView(R.layout.main2);
pageNum=0;
}
return true;
}
return super.onKeyDown(keyCode, event);
}
I'm pretty new to android app development and this form as well; as This is my first post pertaining to my first app store worthy app.
I appreciate the time you spent reading my question, and I know others android noobies will probably run into this same/similar problem and find this useful.