Buggy ListView makes me sad - android

I have a ListView where I've defined the layout of each item in a separate XML file. In this file I've included a RatingBar and an EditText.
I've programmatically created 7-8 items in this ListView. When I scroll through them, it seems to be quite buggy. Here are some examples:
If I set focus to the EditText in the first row and then scroll down the ListView, random EditTexts from other rows will have focus. It seems to be that the next EditText after the focused one disappears receives focus. Perhaps this is intentional, but, as a user, it seems very weird.
If I set focus to an EditText, receive a virtual keyboard, type something, and click the "Done" button on my virtual keyboard, the EditText will empty as soon as the virtual keyboard disappears.
Sometimes, when I click an EditText, receive a virtual keyboard and start typing letters, the letters will disappear as soon as I type them.
When I click on an EditText, the virtual keyboard shows itself, but the EditText loses focus and I have to click the EditText again.
Even though I've set the RatingBar to focusable="false", if I move my scrollwheel, it still grabs focus.
One of my problems is all the visible list items get redrawn when I type a character in the virtual keyboard (and since the text of the EditText is set to some data, which is empty, it gets cleared. I don't understand why Android would decide to redraw the list every time I type a character.
Here is the XML I'm using to draw them. They are white bubbles, with a gray boarder, and some text, a RatingBar and an EditText inside:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:paddingLeft="15dip"
android:paddingRight="15dip"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dip"
android:background="#drawable/shape_outer">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dip"
android:background="#drawable/shape_inner">
<TextView
android:id="#+id/rating_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/dark_gray"
android:textStyle="bold"
android:layout_marginBottom="10dip" />
<RatingBar
android:id="#+id/rating_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="0"
android:stepSize="1"
android:focusable="false"
android:clickable="false"
/>
<EditText
android:id="#+id/rating_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:padding="6dip"
android:textColor="#000000"
android:gravity="left|top"
android:lines="3"
android:hint="Comment"
android:imeOptions="actionDone" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

It sounds like ListViews aren't able to handle EditTexts well. I've done some research and the consensus seems to be "don't do that." So what I've resorted to is creating a simple layout file which is a ScrollView with a LinearLayout inside. In my onCreate method, I inflate the View I was using for my list item and add it to the LinearLayout. I'm also adding the View to an ArrayList so I can save the data in each View later on.
Does this sound reasonable?

Well,add this to your activity in manifest...
android:windowSoftInputMode="adjustPan"
Example...
<activity android:name=".mapview.AddParkingLotActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"/>

I was having the same problem. My EditText inside of LisView was losing focus when the keyboard appears, so on getView from the ListView item I put
final EditText editInput = (EditText)convertView.findViewById(R.id.edit_input);
editInput.requestFocusFromTouch();
And this work for me.

These two steps resolved a similar issue I had (EditText on a row within ListView + funny keyboard behavior).
Add android:windowSoftInputMode="adjustPan" attribute into
AndroidManifest.xml file on the activity where the ListView is
presented.
Add android:descendantFocusability="afterDescendants" attribute onto the ListView itself.
This is the actual example:
AndroidManifest.xml
<activity
android:name=".SubscriptionListActivity"
android:windowSoftInputMode="adjustPan"
android:label="#string/title_activity_subscriptions" >
</activity>
layout.xml file
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:id="#+id/subscriptionList" />
I tested it on Samsung Galaxy S3 and it works fine with Samsung as well as SwiftKey keyboards.

i have some issue i solved just commenting this line
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Related

Android ScrollView, under Action Bar on Softkeyboard

I've read several discussions around this issue and it has to do with the android:windowSoftInputMode="stateHidden|adjustResize" (as well as adjustPan) of the manifest file when attempting to get a ScrollView of a LinearLayout to adjust when the keyboard is shown.
I have a layout that has a LinearLayout inside of a ScrollView that contains 10 LinearLayout sections (TextView/EditText views). I have tried every combination I have read about and no matter what, when the keyboard is opened as a result of clicking on the top EditText, the view is adjusted (panned) such that the top field is behind the action bar. I can scroll to the bottom of the page, but I can't get to the top EditText - I can only scroll to the 2nd one. I can try and pull down and I can start to see the top EditText but can't get it to show unless I dismiss the keyboard (which obviously I can't edit the text then).
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.myproject.FirstActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
tools:showIn="#layout/activity_work"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="x1"
android:layout_weight="50"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/work_one"
android:hint="0"
android:gravity="right"
android:selectAllOnFocus="true"
android:textAlignment="gravity"
android:layout_weight="50" />
</LinearLayout>
.
. (9 more of these)
.
</LinearLayout>
</ScrollView>
UPDATE:
so I tried: android:windowSoftInputMode="adjustResize" and / or android:windowSoftInputMode="adjustPan" and the soft keyboard shifts the top fields under the action bar.
Thoughts?
Try either android:windowSoftInputMode="adjustResize" or android:windowSoftInputMode="adjustPan"
From the doc
"adjustResize"
The activity's main window is always resized to make room for the soft keyboard on screen.
"adjustPan"
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
I copied the answer from this Stack Overflow answer

Android Soft Keyboard not showing all `EditText`

First off all let me say that I've tried in the manifest android:windowSoftInputMode="adjustPan|stateHidden" and android:windowSoftInputMode="adjustResize|stateHidden" and the result is the same.
I have a layout with an Header and a Footer and in between I have an ScrollView. Inside this, I have a RelativeLayout and inside this layout, I have one EditText and a LinearLayout containing another EditText (this layout makes sense in my app).
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scroll"
android:layout_below="#+id/header"
android:fillViewport="true"
android:layout_above="#+id/footer">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="40dp">
<EditText
android:id="#+id/one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/edittextback"
android:layout_marginBottom="40dp" />
<LinearLayout
android:id="#+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/one"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
android:layout_marginBottom="40dp">
<EditText
android:id="#+id/two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittextback"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
When I enter the activity and start entering text in the first edittext, the keyboard pops up, the scroll goes up a little so the I can see the text that I'm inserting. The problem is that the edittext is not all visible (I mean the bottom boundary). The keyboard stays just bellow the inserted text and not bellow the bottom of the edittext.
Now, since I already have the keyboard open, I scroll a bit so that I can see the top of the second edittext. When I touch the second edittext, it gains focus, and now, it automatically scrolls a bit not like the first edittext, that is, just enough to see the inserted text, but to the bottom of the edittext making the edittext all visible. This is what I want.
How can I make the behavior to be show always all the edittext?

Android: Fixed Number Pad

I have an EditText and when clicked a numberpad slides up via android:inputType="number". When this happens though it pushes the TextViews above off of the screen. I was wondering if there was a way for the numberpad to always be shown (then I can have fixed positions for everything)?
(I do not have a lot on the activity, so it is not like I am trying to save space.) I want the user to be able to see the TextViews that get pushed off the screen because they are updated based on the input. Here is what it looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Name" >
// TextViews that get pushed off
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="71dp"
android:layout_toLeftOf="#+id/enter_input"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
</RelativeLayout>
Is this possible? Or is there a better way so everything is shown on the screen and so nothing is hidden?
You can add android:windowSoftInputMode="stateAlwaysVisible" to your activity in AndroidManifest.xml so it forces the keyboard to always show.
<activity android:name="[activity_path]" android:windowSoftInputMode="stateAlwaysVisible"/>

Android layout - listview and edittext below

I'm trying to mimic the behaviour of the HTC SMS application (tradional view), where all messages are shown, and an EditTextis shown below. As you can see in the screenshot, when scrolling upwards, the EditText scrolls away at the bottom.
I'm stuck with this, even after reading multiple posts (eg Android Layout with ListView and Buttons and this website: http://www.finalconcept.com.au/article/view/android-keeping-buttons-visible), it's not working as expected.
Thanks to the comments and EditText now showing under ListView, I've managed to have my ListView take all available space and start scrolling once completed. The EditText is showing at the bottom of the screen now - always. I'd like it to disappear at the bottom when I scroll up though - now it remains at the bottom
Current Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#android:id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TableLayout
android:layout_weight="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<EditText android:id="#+id/newmessagecontent"
android:layout_height="150dp"
android:singleLine="false"
android:gravity="top"
android:layout_width="250dp"
android:layout_alignParentTop="true"
/>
<Button android:layout_height="wrap_content"
android:id="#+id/sendmessage"
android:text="Send"
android:layout_width="wrap_content"
/>
</TableRow>
</TableLayout>
</LinearLayout>
i think what you need to implement here is some sort of modification of the SeparatedListAdapter from Jeff Sharkey from this Article. In this article he not only manages to add two Adapters to a ListView but also explains how to have Headers to separate them if you want (you can remove that part of the code).
So what i mean, is your first Adapter will be the data with It's rows, and the second Adapter will be a dummy one with no data that just points to a View with your controls or whatever.
this way the ListView and what you want to add at the bottom are gonna be all scrollable.
Hope this helps.
A ListView automatically scrolls if all the items in it take up more space than the view provides. What happens if you remove the ScrollView?

Making the vertical scrollbar visible

I want to make the vertical scroll bar permanently visible. Currently the scroll bar appears only when I attempt to scroll the text view enclosed inside the scroll view. This is my XML declaration.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/radio_group"
android:layout_margin="5dp"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true" >
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#FF000000"
android:textStyle="bold" />
</ScrollView>
Thank you for your time.
You can set android:fadeScrollbars="false" in your ScrollView XML.
We can do it in 2 different ways as shown below.
Method 1: in your XML
android:scrollbars="vertical"
android:fadeScrollbars="false"
Method 2: in your Java Code
editText.setVerticalScrollBarEnabled(true);
editText.setVerticalscrollbarFading(false);
View.setScrollbarFadingEnabled(boolean) seems to be what you're looking for (never tried it though). Here View is the ScrollView on which you want the scrollbars to not fade. And set the boolean value to be false.
if you do it dynamically, it shows runtime error and the scroll is not visible
EditText edit = (EditText) find ViewById(R.id.EditText1);
edit.setVerticalScrollBarEnabled(true);
edit.setVerticalscrollbarFading(false);
there is no way to show it dynamically

Categories

Resources