Managing view's refresh delay and soft keyboard

by Mirthis » Tue, 09 Jun 2009 01:19:07 GMT


Sponsored Links
 I repost here what I've already written on the Android Developer group
cause it fit better here.

Hi to everyone. I start trying out some stuff with Android from few
days so there's lot I don't know but I hope not to sound too stupid.
Here are the first problems I'm facing

1) I have a ListView where each item is made of two icon (on the left
and right side) and an EditText, disabled, in the middle. I have a
button to add new element to the lists and what I want to happen is
that clicking on it a new lne appears in the ListView with the focus
on the EditText so that the user can type a label for the object.
What I tried to do when the button is clicked is:
- add a new object to the array binded to the ListView;
- notify the array adapter that a change as occoured in the data
- retrieve the view object for the last child added to the ListView
- set the focus on the EditText
The problem is that between the call of notifyDataSetChanged() and the
 creation of a new child in the ListView there's a delay and so I'm
not able to get the new created view in the click handler. What's the
best way to handle it?

2) Considering the same scenario when I give focus to the EditText I
see the cursor for editing the field value but the soft keyboard
doens't appear. That's perfect on a device with an hard keyboard, but
what would happen if the device doesn't have one?
The other thing I find weird is that when I tap the EditText the
keyboard finally appears but the field lost the focus so I can type
whatever I want but nothing appear in the field. This latest thing
seems to be in some way related to the fact the EditText is part of
the layout used to display each item in the list. Any idea on how to
solve it?

That's all, I hope it was fairly clear and to get some help.
Thank you for reading

Andrea

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Trouble inflating a view

I am trying to use a grid with a custom component but when I try to
inflate the view I get the following exception:

12-02 04:18:07.790: ERROR/AndroidRuntime(1146): Uncaught handler:
thread main exiting due to uncaught exception
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):
java.lang.ClassCastException: android.widget.AbsListView$LayoutParams
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.LinearLayout.measureVertical(LinearLayout.java:323)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.LinearLayout.onMeasure(LinearLayout.java:275)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.GridView.onMeasure(GridView.java:937)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.FrameLayout.onMeasure(FrameLayout.java:208)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.LinearLayout.measureVertical(LinearLayout.java:461)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.LinearLayout.onMeasure(LinearLayout.java:275)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.widget.FrameLayout.onMeasure(FrameLayout.java:208)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.View.measure(View.java:6621)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.ViewRoot.performTraversals(ViewRoot.java:620)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1103)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.os.Handler.dispatchMessage(Handler.java:88)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.os.Looper.loop(Looper.java:123)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
android.app.ActivityThread.main(ActivityThread.java:3742)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
java.lang.reflect.Method.invokeNative(Native Method)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
java.lang.reflect.Method.invoke(Method.java:515)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:739)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
12-02 04:18:08.030: ERROR/AndroidRuntime(1146):     at
dalvik.system.NativeStart.main(Native Method)

Here is the code I am using to try to inflate the view:

@Override
public View getView(int index, View convertView, ViewGroup parent)
{
        View iconLayout;
        ImageView icon;
        TextView fileName;

        if (convertView == null)
        {
                iconLayout = View.inflate(FileBrowser.this, R.layout.icon, 
null);

                icon = (ImageView)iconLayout.findViewById(R.id.Icon);
                icon.setScaleType(ImageView.ScaleType.FIT_CENTER);
                icon.setLayoutParams(new GridView.LayoutParams(50, 50));

                fileName = (TextView)iconLayout.findViewById(R.id.FileName);
        }
        else
        {
                iconLayout = convertView;
                icon = (ImageView)convertView.findViewById(R.id.Icon);
                fileName = (TextView)convertView.findViewById(R.id.FileName);
        }

        icon.setImageResource(getIcon(index));
        fileName.setText(mFiles.get(index).getName());

        return iconLayout;
}

and here is the layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:id="@+id/IconLayout">

        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/Icon"
                android:maxHeight="48px"
                android:maxWidth="48px"
                android:minHeight="48px"
                android:minWidth="48px" />

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/FileName"
                android:maxLength="15"
                android:maxLines="1" />
</LinearLayout>

Does anyone know what is causing this exception?
--~--~---------~--~----~------------~-------~--~----~

2. rebuilt browser to g1

I changed the user agent variable (from 0 to 2) in the source code,
compiled the source and swapped the system.img files in the android
SDK emulator images folder (/android-sdk-linux_x86-1.0_r1/tools/lib/
images/system.img).

The emulator loads the new browser fine and displays an iPhone user
agent string. (the setUserAgent() method in webview.websettings has a
preset function to set user agent as iphone).

What i dont know how to do, is get the browser that i created, off the
emulator and onto my physical g1.
I tried loading the files located in ~/bin/mydroid/packages/apps/
Browser into the folder created when i created a new project in
Eclipse using the file name Browser, activity name com.android.browser
etc. (matching the file as if it were alone) but when i tried to build
just the browser application eclipse throws 100 errors and 49
warnings.
I assume this is because there are file dependancies that exist in
their proper places in the source code, but not when i try to compile
just the browser application.

What do i need to do to compile the browser and create a .apk file i
can transfer to my g1?

Any help is appreciated,
 thanks

Ian

--~--~---------~--~----~------------~-------~--~----~

3. Is it mandatory to call the getSystemService() function by ecvery application?

4. Jezelle

5. What is the name of email client in android?

6. Sending SMS on multiple emulator instances.

7. Who maintains / supports Android core applications like MMS / Contacts / etc.?