views:

662

answers:

6

Hi everybody,

I know the attribute which makes the text "disapear" on the left part of the Edittext to maintain a single line, (singleLine="true"). But my issue is when I fill the edittext before the view is displayed... in this case, my edittexts are all going out of the screen... any ideas? thx!

This is what is get when fill the empty Edittext. Everything stays put, and the text is vanishing on its left side

Screenshot

and when I prefill from my DB

Screenshot

here is the code of the edittext :

<EditText android:id="@+id/InscripChampNom"
android:layout_height="wrap_content" android:textSize="14px"
android:inputType="textPersonName" android:layout_marginRight="20dip"
android:singleLine="true" android:textColor="@color/background"></EditText>

The tableLayout is defined as follows:

<TableLayout android:layout_width="fill_parent"
android:stretchColumns="1" android:layout_height="fill_parent">

I also tried with the attribute

android:layout_width="fill_parent"

and

android:layout_width="wrap_content"

no success at all...

Maybe there is a conflict between input type and singleline?

EDIT Here is the full code of my issue :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" android:background="@color/backgroundzen"
android:layout_gravity="fill" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="6dip"
android:paddingRight="6dip">
<TableLayout style="@style/LayoutWhiteBgrdFillWrap"
    android:paddingLeft="6dip" android:paddingRight="6dip"
    android:stretchColumns="1">
    <TextView android:id="@+id/NomFormationConference" style="@style/textViewTitleRedzenBold"
        android:text="Nom conférence"></TextView>
    <TableRow android:layout_margin="2dip">
        <TextView android:id="@+id/DateSession" android:textColor="@color/textezenrouge"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="date début"></TextView>
        <TextView android:id="@+id/speakerConf" android:textColor="@color/textezenrouge"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="speaker"></TextView>
    </TableRow>
    <TableRow android:layout_margin="2dip">
        <TextView android:id="@+id/InscripNom" android:layout_width="wrap_content"
            android:textColor="@color/background" android:layout_height="wrap_content"
            android:text="@string/nom" android:textStyle="bold"></TextView>
        <EditText android:id="@+id/InscripChampNom"
            android:layout_height="wrap_content" android:textSize="14sp"
            android:layout_width="fill_parent" android:inputType="textPersonName"
            android:layout_marginRight="20dip" android:hint="@string/nomh"
            android:singleLine="true" android:textColor="@color/background"></EditText>
    </TableRow>

//The last tablerow is repeated 5 times with various data inside.

The style is like that :

<style name="LayoutWhiteBgrdFillWrap">
    <item name="android:background">@color/backgroundzen</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>
</style>

And here is how I fill the EditText :

misc = SQLiteDatabase.openDatabase("/data/data/com.mobile.zen/databases/" + Constants.UNVERSIONNED_DATABASE, null,
            SQLiteDatabase.OPEN_READONLY);
    Cursor c = misc.query("MISC", null, null, null, null, null, null);
    if (c.moveToFirst()) {
        do {
            nomInscrit.setText(c.getString(1));
        } while (c.moveToNext());
    }
    c.close();
    misc.close();
A: 

You have no android:layout_width attribute on your EditText. Add one or otherwise constrain how long the field can be (e.g., if it is in a RelativeLayout, use android:layout_alignParentRight="true").

CommonsWare
it's not working ... I tried wrap_content and fill_parent as width, but none worked.These edittext are in a tablelayout with the strech column applied to their column.. if it can help...
Sephy
A: 

Hi Sephy,

I am facing the exact same problem within the table layout. Were you able to find a way to avoid the field stretching?

Ashish
actually,no... I still get weird stretching when i get stuff out of the database into the field....sorryI'm thinking of starting a bounty...
Sephy
Don't make a new answer for this. This should be a comment on the first question.
Moncader
Look at walter's answer, he got it right.
Sephy
A: 

I just tried to reproduce your issue but I couldn't.

Check this:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:stretchColumns="1"
    android:layout_height="fill_parent">

    <EditText android:id="@+id/a" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

    <EditText android:id="@+id/b" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

    <EditText android:id="@+id/c" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

</TableLayout>
Macarse
Ok, wait, I'll update my first post with full code so that you can see.
Sephy
Full code updated! Still not working
Sephy
Did this give you any inspiration?
Sephy
+1  A: 

Try adding android:shrinkColumns="1" to your TableLayout to tell it that it can force the EditText items to be smaller to fit into the width of the screen.

Walter Mundt
Sorry but I don't understand your answer. You refer to column 1 but speaks of the TextView...Which one should I use?
Sephy
The column numbers are zero-based, so column 1 is the second column -- the one containing your TextView widgets. Thus, setting that attribute on the `TableLayout` affects those.
Walter Mundt
Indeed, setting the shrinkColumns="1" (the column with the EditText being the source of the issue) did the trick. Thanks VERY MUCH. I owe you 100 reput. But I can't find the bounty button anymore...
Sephy
The bounty expired (they last a week), so your hundred points have evaporated. Best you can do now is click the checkmark by the answer to accept it, which is good for 15. Glad to help though. I edited the answer to change the widget name, sorry for the confusion.
Walter Mundt
A: 

Might be a possible bug in Android. But one way to solve it may be is to specify some value as a width to the Edit Text box and specify

android:stretchColumns="1"

   <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" android:background="#ffffff"
android:layout_gravity="fill" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="6dip">
  <TableLayout android:layout_below="@+id/reltable1" android:id="@+id/tablelayout_main" android:layout_width="fill_parent" android:layout_marginRight="10dip" android:layout_marginBottom="10dip" android:layout_height="fill_parent" android:layout_centerInParent="true" android:gravity="center" android:stretchColumns="1">
    <TextView android:id="@+id/NomFormationConference" 
        android:text="Nom conférence"></TextView>
    <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TextView android:id="@+id/DateSession"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="date début"></TextView>
        <TextView android:id="@+id/speakerConf" 
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="speaker"></TextView>
    </TableRow>
      <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TextView android:id="@+id/InscripNom" android:layout_width="wrap_content"
           android:layout_height="wrap_content"
            android:text="nom" android:textStyle="bold"></TextView>
        <EditText android:id="@+id/InscripChampNom"
            android:textSize="14sp"
            android:inputType="textPersonName"
            android:hint="nomh" android:text="dsfdsfdsfsdfsdfsssssssssssssssssssssssssssssss" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:layout_width="220dip" android:ellipsize="end"></EditText>
    </TableRow>
</TableLayout>
</ScrollView>

I have also Added height and width property for TableRow

Rahul
A: 

Instead of Wrap content use a fixed value in px.

This is not a good suggestion, fix value prevents handling easily multiple screen resolution.
Sephy