Android : Get A ListView And TextView To Scroll As One Unit?

Oct 11, 2010

I have a main menu screen with a simple ListView that contains "links" to further screens in my app (Browse, Bookmarks, Settings, About, etc.). Underneath the ListView there is a TextView (more accurately, a TextSwitcher that rotates TextViews) that changes every 10 seconds to display a new "tip".

In portrait mode, this works fine. There are my five list items in the ListView , and my tip label underneath. However, when I switch to landscape mode, the ListView is taller than the screen. The ListView scrolls normally, but I cannot scroll past the end of the ListView to see the TextView underneath.

I have tried every possible combination of Layouts, wrappers, ScrollViews, and layout_height parameters and I simply cannot get it to behave.

Here is the simplest code ...

Like I've said, I've already tried so many different combinations that I can't list them, and for the most part I was randomly inserting XML in an attempt to get something to work the way I wanted. So I'd greatly appreciate suggestions as to how I would go about doing this the right way.

Android : Get a ListView and TextView to scroll as one unit?


Android :: Why Does TextView.setText Cause Enclosing Scroll View To Scroll?

Jun 24, 2010

I've got this odd problem which is happening on 1.6, 2.2, and a MyTouch 3G Slide (which is API #7, and listed as "2.1-Update1" in the Android Device Chooser). If anyone can explain what I'm doing wrong & how to fix it (or possibly confirm that this is an Android bug)The basic idea for my app is to make a stopwatch-sort of thing, in that the user can tap a button to start a timer, then tap it again to stop (pause) the timer; further taps alternate between resuming the timer and pausing the timer.I've got a top-level ScrollView which contains a RelativelLayout, which contains a bunch of widgets. The first widget is a HUGE button (so that it's easy to press), which pushes all my other widgets below the bottom of the screen. This is intentional, as I want to rely on the ScrollView (and an on-screen reminder to the user) to make the rest of the input options available.I've got a simple state-machine type setup, where mState is the current mode (STATE_ TIMER_ NOT_ STARTED before the user presses any buttons, RUNNING after the first press, and then PAUSED after the second, back to RUNNING after the third, etc, etc).

All this works great EXCEPT that when the timer is running, and the user presses the start/stop/resume button again, the ScrollView will scroll down a ways. I am NOT issuing this command (I don't even have a reference to ScrollView object), and I'm not sure why it's doing this.

REPRO:Compile + run the below samples. When the app starts, press the 'Start Timing' button. Use your thumb (or the mouse) to touch-drag the screen upwards (so you can see the RatingBar), then drag it back downwards (so the button is again completely on-screen). Tap the button (which now reads 'PauseTiming') again, and it'll jump down a bit. It should NOT be jumping/scrolling down, since there's no statement (that I can see) that tells it to scroll down. As near as I can tell, it's the setText that causes the scrolling ( when I comment those lines out, no scrolling occurs).WHAT I'M ASKING FOR:if I'm doing something dumb & you could point out what it is, I'd really appreciate it! I wonder if 'touch mode' might have something to do with this, since it does NOT appear to happen (in the emulator) when I use the mouse's scroll wheel to move the panel upwards (i.e.,instead of the simulated finger-dragging). I can't find a whole lot on touch-mode, and nothing specific on focus/selection in touch mode within a ScrollView if you can confirm that this error occurs for you too, that would be ok, too (since misery loves company.AHEM I mean, since it might help confirm that it's not just me MyTestApp.java package bug.android.scrollview;
import android.app.Activity;
import android.os.Bundle;
import android.text.format.Time;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
public class MyTestApp extends Activity {
public final static int STATE_TIMER_NOT_STARTED = 1;
public final static int STATE_TIMER_RUNNING = 2;
public final static int STATE_TIMER_PAUSED = 3;
private int mState;
Time t = new Time();
private Time data = new Time();
private Button btnStartStopResume;
private TextView lblSpacer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_time_entry);
btnStartStopResume = (Button) findViewById(R.id.btnStartStopResume);
// Set the button's size so that the other info will also be visible
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
// This is such a hack, but the windowScroller doesn't appear to
// have a height at this point in the lifecycle (nor in 'onResume' :( )
btnStartStopResume.setHeight(display.getHeight() - 200);
lblSpacer = (TextView) findViewById(R.id.lblSpacer);
reset();
} public void doStartStopResume(View v) {
if (mState == MyTestApp.STATE_TIMER_NOT_STARTED) {
mState = MyTestApp.STATE_TIMER_RUNNING;
data.setToNow();
} else if (mState == MyTestApp.STATE_TIMER_RUNNING) {
mState = MyTestApp.STATE_TIMER_PAUSED;
String s = getString(R.string.add_scroll_down_to_add);
lblSpacer.setText(s);
} else if (mState == MyTestApp.STATE_TIMER_PAUSED) {
mState = MyTestApp.STATE_TIMER_RUNNING;
public void doReset(View v) {
}public void doNewRunClick(View v) {
public void doAddTiming(View v) {
public void reset() {
mState = STATE_TIMER_NOT_STARTED;
new_time_entry.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/windowScroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <Button
android:id="@+id/btnStartStopResume"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Start Timing"
android:textSize="40dp"
android:height="290dp"
android:onClick="doStartStopResume" />
<TextView
android:id="@+id/lblSpacer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnStartStopResume"
android:layout_centerHorizontal="true"
android:text="@string/add_scroll_down_for_more" />
<TextView
android:id="@+id/lblTimeStartLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lblSpacer"
android:layout_alignParentLeft="true"
android:clickable="true"
android:onClick="adjustStartTime"
android:text="Start of this run:"
android:textSize="8dp" />
<TextView
android:id="@+id/lblTimeStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblTimeStartLabel"
android:layout_alignParentLeft="true"
android:clickable="true"
android:onClick="adjustStartTime"
android:text="--:--:-- --"
android:textColor="#FFFFFF"
android:textSize="26dp" />
<TextView
android:id="@+id/lblElapsedLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblSpacer"
android:layout_alignRight="@id/lblSpacer"
android:layout_marginRight="5dp"
android:text="Elapsed Time:"
android:textSize="8dp" />
<TextView
android:id="@+id/lblTimeElapsed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblElapsedLabel"
android:layout_alignRight="@id/lblSpacer"
android:layout_marginRight="5dp"
android:textColor="#99ff66"
android:text="-- m -- sec"
android:textSize="26dp"
android:layout_marginBottom="10dip"/>
<CheckBox
android:id="@+id/chkNewRun"
android:onClick="doNewRunClick"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lblTimeElapsed"
android:text="This is a new run of timings"
android:layout_marginBottom="10dip" />

<TextView
android:id="@+id/lblIntensity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Intensity (1 = none 5 = max)"
android:layout_below="@id/chkNewRun" />
<RatingBar
android:id="@+id/rbIntensity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblIntensity"
android:numStars="5"
android:rating="2"
android:layout_marginBottom="5dip" />

<TextView
android:id="@+id/lblNotes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Notes:"
android:layout_below="@id/rbIntensity" />
<EditText
android:id="@+id/txtNotes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/lblNotes"
android:layout_marginBottom="10dip" />
<Button
android:id="@+id/btnReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtNotes"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:text="Reset"
android:onClick="doReset" />
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtNotes"
android:layout_toRightOf="@id/btnReset"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:text="Add Timing To List"
android:onClick="doAddTiming" />
</RelativeLayout>
</ScrollView>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Timer</string>
<string name="dlg_edit_timing_title">Edit A Timing</string>
<string name="add_scroll_down_for_more">< Scroll down for more options! ></string>
<string name="add_scroll_down_to_add">< Scroll down to save this timing! ></string>
<string name="start_timing">Start Timing
</string>
<string name="stop_timing">Pause Timing
</string>
<string name="resume_timing">Resume Timing
</string>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bug.android.scrollview"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyTestApp"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="5" />
</manifest>
UPDATE 1: Adding if( btnStartStopResume.isInTouchMode() )
Toast.makeText(this, "TOUCH MODE", 2000);
elseToast.makeText(this, "NOT touch mode", 2000);
then setting breakpoints in the debugger confirms that the button is always in touch mode (regardless of whether I finger-drag the panel up/down, or mouse-wheel it up/down). So it's a combination of being in touch-mode AND finger-dragging the panel after the 2nd button-press (i.e, when the app is in 'stopped/paused timing' mode) that's causing the odd extra-timing in subsequent pauses.
UPDATE 2:
I just noticed that it's scrolling down to the EditText, and no further. It looks like when you move the panel down the EditText gets the selection, and after the click event the ScrollView scrolls back to the thing that has the selection. Seems to explain why the mouse-wheel approach doesn't have this problem (it moves the selection/focus back up to the button).

View 1 Replies View Related

Android :: Scroll A TextView To Specific Line?

Dec 22, 2009

I have a TextView inside a ScrollView. Let's say the ScrollView is named s and the TextView is named t.

I have many lines to be displayed in the TextView and at the same time I want to scroll the view to a specific line.

So I did this:

t.setText(aVeryLongString);
int y = t.getLayout().getLineTop(40); // e.g. I want to scroll to line 40
s.scrollTo(0, y);

But it won't scroll, except the second time. It seems that on the first time the code finishes, the ScrollView knows how much the total height of the TextView is.

So I think there must be something to force calculating the needed height before the scrollTo call. How to do that (or otherwise)?

View 1 Replies View Related

Android : TextView Supposed To Be Able To Scroll Its Contents?

Nov 10, 2009

It was my understanding that even though TextView is not a ScrollView, it has scrolling functionality built-in.

However, I'm not able to scroll the contents of a TextView (that's on 1.6). I've reduced my code to the most trivial example:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical"> Code...

I then defined a really long string for testing, which I set on this text view using setText(). The text is too long for the TextView, but there is no way to scroll it. So do I need to wrap it in a ScrollView after all?

View 2 Replies View Related

Android :: Page Up / Down Of TextView Inside Of Scroll View

Aug 17, 2010

I have a ScrollView, inside of it there is a TextView, and there are two buttons for PageUp and PageDown in the other part of the layout. When I click on PageDown, I want to see the text in the TextView to scroll down one page. How could I do it?

View 2 Replies View Related

Android : First And Last Position Of Textview From Horizontal Scroll View

Aug 26, 2010

I have a horizontal scrollview with text fields,here i need to get the first and last position of textview when i scrolled it,how can i get the position of textview when i scrolled.and also need to know how to set color for text when i clicked the particular text from this. sample code....

View 1 Replies View Related

Android : Scroll / Move Text Within TextView On Home Screen Widget?

Apr 21, 2010

I have created a widget to be displayed on android emulator's home screen to display some long text. In my main.xml layout file i've already set TextView properties like singleLine="true", ellipsize="marquee", focusable="true" etc, but still when my widget is displayed on home screen text does not move/scroll.code...

View 7 Replies View Related

How To Make TextView Inside ViewPager Scroll Vertically

Jul 3, 2012

I've got a ViewPager and a TextView inside it. When content of TextView is larger then it is visible on screen, there shall be possibility to scroll it vertically. But it does not do this automatically.Here is an xml for TextView

Code:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/txText"
android:layout_width="fill_parent"
[code]...

View 5 Replies View Related

Android :: ListView And Other Widgets Scroll As Whole

Jul 23, 2009

- 2 input boxes where the user can enter criteria to search for - 1 search button - when the search button is clicked, a search is performed and on the same page the matches are shown *below* the 2 input boxes and search button. - the results can be quite a few (say up to 50), which won't fit all on the viewable part of the screen, so the user has to be able to scroll down in the results. - when the user scrolls down over the results, the 2 input boxes + search button should of course also scroll up out of sight.

Basically the behaviour you get when you for example do a google search on google.com. But, for clarity: I don't want to use the WebView. Note that there should be no scrollbar for the results only (that can be done easily with a standard ListView), the all needs to scroll as a whole. The reason I want this behavior is that I don't want to direct the user to a next screen with the search results; that would be so annoying having to go back to the "search" screen all the time if you want to enter another search criteria, like if you figured out you made a typo.............................

View 5 Replies View Related

Android :: Horizontal Scroll In ListView

Mar 26, 2010

I would like to catch horizontal scrolling in ListView. I don't wont to scroll ListView content, I need an event only. I use GestureDetector, and in onScroll() method I can figure out when user scrolls in horizontal direction. This part works. But my problem is ListView fires onItemLongClick event also. I need this event, but only if user doesn't scroll. If user scrolls in vertical direction, ListView doesn't fire onItemLongClick event. I need the same behavior for horizontal scrolling also.

View 2 Replies View Related

Android :: ListView Scroll Up / Down Without Gestures

Nov 5, 2009

I'm trying to scroll the ListView up/down actions by pressing a button, instead of using finger gesture. It looks like the super class AbsListView.onTouchEvent(MotionEvent ev) handles all the scrolling up/down motion and animation. So if I want to scroll the list by pressing a button, I don't really have a MotionEvent to pass onto onTouchEvent method for it to work. I tried ListView.scrollTo(x,y), it kind of works but the hidden part of the ListView is not rendered when shown on the screen. I am trying to re-draw the list by using: ListView.invalidate(), ListView.invalidateViews(), list.adapter.notifyDataSetChanged()

View 3 Replies View Related

Android :: View And ListView Scroll At Once?

Oct 22, 2009

What I have now is a layout that includes a list view at the bottom. All of the items in the layout above the list view remain fixed as you scroll through the list view. I would like the entire page to scroll so for example when you reached the bottom of the list you would no longer see the items above the list view.

View 5 Replies View Related

Android :: Set Scroll Position Of ListView?

Jul 30, 2010

I have a listview displaying my data.Ok. I want to set the scroll position in a position of my choice, but I just cant do it. I used :

myListView.setSelection( anyPosition ); myListView.setSelected(true); and has not worked. I also tried : myListView.scrollTo(0, PositionY); and myListView.scroolBy(0, PositionY);

and there's a strange behavior, this two methods doesn't put the scrool in the "PositionY", it made the "PositionY" be the first position in the list, cutting everything that exist before.

View 3 Replies View Related

Android :: Scroll Speed Of Listview

Apr 24, 2009

Get scroll speed of Listview, Ivan Soto Fernandez Web Developer

View 4 Replies View Related

Android :: Scroll To Position In ListView

Jun 10, 2010

I have a long listView that the user scrolls around and then returns to the previous menu. What I want is that when the user opens this list View again the list to be scrolled to where the it was previously left. Any ideas on how this can be achieved ?

View 2 Replies View Related

Android :: Scroll Two ListView In Layout

Sep 29, 2010

I have 2 ListView in a layout. I want each ListView show all their items. And scroll the whole layout.

View 1 Replies View Related

Android :: Get Rid Of Shadow When I Scroll ListView?

Jul 10, 2010

How can i get rid of the shadow when I scroll ListView.

I have shadows appearing on top and bottom of the list.

View 1 Replies View Related

Android :: Listview Background Image Changes On Scroll?

Apr 30, 2010

I am developing an android application where I need to manipulate the background image of the rows in listview on certain conditions. Initially when the listview is loaded all works properly. But when I scroll down to the listview and come up again the background image changes. Can someone tell me the reason why its happening so? Hope to get the reply soon.

View 6 Replies View Related

Android :: Saving ListView Scroll Location?

Jan 20, 2010

I'm trying to figure out how to save the location my ListView is scrolled to. Currently I am saving the ArrayList of the ListView. When the user comes back to the screen I reload the ArrayList but can't figure out how to make it scroll to the last location.

View 3 Replies View Related

Android :: Scroll Listview To Focus Particular Element?

Jan 30, 2009

I'm trying to scroll my ListView (from an Activity) to a particular element in the list. I know it's position in the list. How is this possible?

View 4 Replies View Related

Android :: Maintaining Scroll Position Of ListView

Apr 7, 2009

In my app, my main class extends ListActivity and calls a fillData() function to reload the list whenever changes are made. I'm still getting the hang of this, so I borrowed that concept from the Android Notepadv1-Notepadv3 tutorials. Everything works great, however whenever I need to change the list (remove an item, re-sort it, edit an item), the ListView refreshes and loses its scroll position. The scroll position is reset to the top after each fillData() call.

It appears to be resetting the scroll position to the top because I'm using setListAdapter() each time in fillData(), setting it to a new SimpleCursorAdapter. How can I get the list to "update in place", where the scroll position is seamlessly maintained to the user? I tried heading down the "items.changeCursor(cursor)" path, but that didn't seam to do much for me.......................

View 2 Replies View Related

Android :: ListView Scroll In Touch Mode?

Feb 18, 2009

i'm rearranging items in the list by dragging the item. I'm in the touch mode and want to scroll view couple of items then i'm on the last/first visiblePosition. Since i'm in the touch mode setSelection is useless. How i can scroll a list in the touch mode. For drag i'm using onTouchEvent , onLayout to change background for the current item + some stuff in adapter to make a swap.

View 3 Replies View Related

Android :: Making Child ListView Scroll

Jan 29, 2010

I am trying to make a terminal type app that is wider than the actual android screen. A listview is great except that I don't want the text to wrap. If the text is wider than the screen I want it to print the full text and then the user can scroll over horizontally if they want to see what was printed off the screen. Just FYI this is for ascii type tables. I have followed this example:

It works great as far as horizontal text goes it does exactly what I want but I am unable to get the ListView inside the custom LinearLayout to actually scroll veritcally. I have tried passing the Y coordinates from the onScroll method to mListView such as: mListView.scrollBy(0, distanceY); but that seems to move the custom LinearLayout window instead of just scrolling the ListView. I can tell that the ListView is not scrolling because the window moves without the vertical scroll bar of the ListView moving.

View 1 Replies View Related

Android :: Scroll To The New Added Item In ListView

May 7, 2010

My application show a ListView with a button which allow user to add an element. When the user clicks on this button, another Activity is started to allow user to populate the new element. When the add is finished, we return to the previous Activity with the ListView and I would like to scroll to the new element.

Note that this element is not necessarily at the end of the ListView because there is an "order by" when I retrieve the datas from the database. I know I need the cursor position of the new element to make the ListView scrool to it, but the only info I have about this element is its id, so how to convert this id to cursor position ? Do I have to loop on the cursor to find the position?

View 1 Replies View Related

Android :: ListView Scroll To Selected Item

Aug 17, 2010

I have a ListView with an edit text and a button below it. When I click on a listView item the keyboard appears and push up the edit text and the button. I want the list to scroll to the selected item.

View 2 Replies View Related

Android :: Listview Scroll To Number Of Listitems

Dec 23, 2009

I am using Listview, i want to scroll down to list's 10 item when view get loaded, how can do that?

View 1 Replies View Related

Android :: ListView : Automatically Scroll To See An Element ?

Feb 19, 2009

I am facing a strange an issue that should simple to solve I suppose. I wonder how can I automatically scroll to see an element in a list view. Let's say I know that I want to see the element view number 6 in my list view, how do I scroll my list to see this element ?

I look at the API but without any success, just a word on where to look.

View 3 Replies View Related

Android :: Scroll ListView With Custom Adapter - Too Fast

Aug 4, 2010

I have a listview with a custom arrayadapter that handles about 15 strings. The style of each row alternates (between labels and values for those labels--for example row 1 could be "email address" and row 2 would be the actual email address). I'm changing the style of each row to alternate like this in the arrayadapter's getView() method. So if the item at the current position is a label, I'll change the styling from the default row style (which is what the values have applied to them). When the listview first loads, the styling is perfect and just how I want it to be. If I scroll the list slowly up or down, it stays that way. However, if I scroll the list fast up and down, the styling of the value rows starts changing to that of the label ones until all of the rows have the styling of a label row. I've used custom adapters on other listviews in the app with no problems like this. Found out that it also changes all of the rows to the label styling on portrait->landscape orientation changes. Doesn't do this on landscape->portrait changes. Below is the adapter I'm using.

public class DetailsAdapter extends ArrayAdapter<String> { private TextView text = null; private String item = null;
public DetailsAdapter(Context context, int resource, int textViewResourceId, String[] objects) { super(context, resource, textViewResourceId, objects);
} @Override public View getView(int position, View convertView, ViewGroup parent) { text = (TextView) super.getView(position, convertView, parent); item = getItem(position);
if (item.equals("Name") || item.equals("Mobile") || item.equals("Home") || item.equals("Email") || item.equals("Address")) { text.setBackgroundColor(0xFF575757); text.setTextSize(15);
text.setTypeface(null, Typeface.BOLD); text.setPadding(8, 5, 0, 5);
} else { text.setPadding(15, 15, 0, 15); } return text;
} @Override public boolean isEnabled(int position) { item = getItem(position);
if (item.equals("Name") || item.equals("Mobile") || item.equals("Home") || item.equals("Email") || item.equals("Address")) { return false;
} else { return true; } } }

View 1 Replies View Related

Android :: ListView Redraws Background Color Whenever Scroll

Sep 23, 2010

I have defined a custom theme, where I am drawing a dark gradient on my window background. My ListView background is set to be transparent, however whenever I scroll, the background color turns black, and then after scrolling has stopped, goes back to the gradient color. Why is this?

CODE:.....................................

View 1 Replies View Related

Android :: Synchronize Two ListView Positions When I Scroll Any One Of Lists

Nov 24, 2010

I have two ListViews. Is there any way to synchronize the position of ListViews when I scroll any one of the Lists

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved