0

Some Background
I have a TableLayout with 9 rows. I chose the TableLayout because I could successfully line up EditText views next to each other on 1 row. I have 6 EditText on two rows as you will see below, but to avoid repetitiveness I am only going to include 2 of the 6 to save on space and I removed some of the unecessary rows because they were displaying properly (just TextView).

The Problem
The problem I am having is after I press the Button on my layout, all of the EditText views disappear. My button initiates contact to a WCF Restful Service, but does so using an AsyncTask. There is a wait dialog to occupy the user and sometimes toast messages pop up. This is all normal behavior. To be perfectly the EditText disappear immediately after I press the button.

I have searched with google and stackoverflow and I have seen similar problems, but not the same problem that I am having. What is very weird is this only happens when I am debugging on my phone, it doesn't happen in the AVD emulator.

Stats
Phone: T-Mobile myTouchQ LG-C800 (FYI: not the greatest phone) I rooted it.
Phone Android Version: 2.3.4 (LG Doesn't believe in updates apparently)
IDE: IntelliJ 11.1
Android SDK : 4.0.3
Java Version: 1.7

Questions
1. Should I use a different layout?
2. Any clue why this is happening?

Here is shortened version of my Layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/tableLayout1"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent" >
    <TableRow android:id="@+id/rowTitleWinningNumbers"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="0dip" >
        <TextView android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Winning Numbers" />
    </TableRow>
    <TableRow android:id="@+id/rowWinningNumbers"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="0dip" >
        <EditText android:id="@+id/txtLotto1"
                  android:inputType="text"
                  android:layout_width="0dp"
                  android:layout_weight="16.67"
                  android:editable="false"
                  android:focusable="false" />
        <EditText android:id="@+id/txtLotto2"
                  android:inputType="text"
                  android:layout_width="0dp"
                  android:layout_weight="16.67"
                  android:editable="false"
                  android:focusable="false" />
    </TableRow>
    <TableRow android:id="@+id/rowTitlePlayerNumbers"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="0dip" >
        <TextView android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Your Numbers" />
    </TableRow>
    <TableRow android:id="@+id/rowPlayerNumbers"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="0dip" >
        <EditText android:id="@+id/txtPlayer1"
                  android:inputType="text"
                  android:layout_width="0dp"
                  android:layout_weight="16.67"
                  android:hint="@string/strDefaultNumber" />
        <EditText android:id="@+id/txtPlayer2"
                  android:inputType="text"
                  android:layout_width="0dp"
                  android:layout_weight="16.67"
                  android:hint="@string/strDefaultNumber" />
    </TableRow>
    <TableRow android:id="@+id/rowPlayerStatus2"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:gravity="center">
        <Button android:id="@+id/btnSubmit"
                android:text="Did I Win?!"
                android:onClick="btnSubmit_onClick" />
        <CheckBox android:id="@+id/cbxSavePlayerNumbers"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:gravity="center"
                  android:lines="2"
                  android:text="Save my \nNumbers" />
    </TableRow>
</TableLayout>

EDIT The code as requested in the comments

public void btnSubmit_onClick(View v)
{
    try
    {
        clearStatuses();

        setLabelText(R.id.lblTimeStamp, DateTime.Today().toString());

        savePlayerNumbers();

        //This method has to perform its main task asynchronously
        getWinningLotteryNumbers();
    }
    catch(Exception ex)
    {
        ex.toString();
    }
}

private void getWinningLotteryNumbers()
{
    try
    {
        _waitDialog = ProgressDialog.show(MyActivity.this, "Working", "Getting latest Lottery drawing, Please Wait...", true);

        getButton(R.id.btnSubmit).setEnabled(false);

        String strUrl = getRString(R.string.strWCFServiceURL);

        new LottoProxy().execute(strUrl);
    }
    catch (Exception e)
    {
        resetControlStates();
    }
}

private void clearStatuses()
{
    TextView lblStatus = getLabel(R.id.lblStatus);
    lblStatus.setText("");
    lblStatus.setTextColor(Color.BLACK);

    for (int i = 0; i < 6; i++)
        resetTextBoxBackResource(getWinningBox(i), getPlayerBox(i));
}

I am supremely stuck on this, so thank you in advance for your help. This is my first real app (as opposed to just playing around), so if I made a novice mistake please let me know.

dyslexicanaboko
  • 4,215
  • 2
  • 37
  • 43
  • 1
    Could you add the code related to your `onClick()` method? – iTurki Aug 08 '12 at 22:22
  • Yes I can, the only issue is that it is a lot of code. Let me know if you want to see a method's body or need an explanation. – dyslexicanaboko Aug 08 '12 at 22:28
  • I think the disappearance has something to do with the button code not the layout. – iTurki Aug 08 '12 at 22:31
  • Ha, didn't expect that. I wonder. Well the code is there for your viewing pleasure. Just so you know the LottoProxy class is just a class that extends AsyncTask so it can hit my WCF service. – dyslexicanaboko Aug 08 '12 at 22:34
  • I finally had a chance to debug this again and I can say without a doubt in my mind it is not the code in the btnSubmit_onClick handler. I commented out ALL of the code in the btnSubmit_onClick handler, ran my app, press the "Did I Win?!" button and the EditText STILL disappear, I have no idea what to make of this. – dyslexicanaboko Aug 23 '12 at 15:37

1 Answers1

0

So it turns out that the EditText were not disappearing, but were hidden from view because of my clearStatuses() method which iterates through all of the available EditText and changes their backgrounds to Black. This is not the wait to handle this because apparently when doing this you are overwriting the stock EditText background image.

The mind boggling part is (as I said in my comments above) I commented out all of the code in the onClick() method and this still happened anyhow. Therefore pin pointing the problem was rather difficult and confusing. I wonder if this is a bug in Android?

I learned to use the following code to change your EditText back to the way it usually looks:

yourEditText.setBackgroundResource(android.R.drawable.editbox_background_normal);

I found this answer here: Removing the background color of an EditText

A word of warning, even though this code will revert the EditText back to what it looks like, it may not match the original look. I am saying this because that is what I experienced, but it is good enough for me.

Community
  • 1
  • 1
dyslexicanaboko
  • 4,215
  • 2
  • 37
  • 43