1
I have a screen that the user changes their data, and as validation I use the setError() to specify which element has the incorrect value. But I have a problem when I have scroll on the screen, the message from setError() simply override Actionbar. I’ve researched some ways to solve this problem, but none are efficient.
Picture of the situation
UPDATE
Follows the layout I’m using.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ECEDEE"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="10dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="9dp"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/fundocomsombra"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/textCadastroDescricao"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorTextGray"
android:gravity="center"
android:textSize="16sp"
android:text="@string/cadastro_descricao" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:paddingBottom="6dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/fundocomsombra"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/textCadastroPlaca"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:text="@string/cadastro_placa"
android:layout_marginLeft="3dp" />
<EditText
android:id="@+id/editCadastroPlaca"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:textSize="16dp"
android:singleLine="true"
android:maxLength="8"
android:hint="Digite sua placa" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btProsseguir"
android:paddingTop="11dp"
android:paddingBottom="11dp"
android:background="@layout/fundoverdepressed"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cadastro_prosseguir_btn"
android:gravity="center"
android:textColor="@android:color/white"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/llRestoCadastro"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/fundocomsombra"
android:gravity="center_horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/llOpcoesCadastro"
android:visibility="visible">
<TextView
android:id="@+id/textCadastroNome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_nome"
android:visibility="visible" />
<EditText
android:id="@+id/editCadastroNome"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:singleLine="true"
android:visibility="visible"
android:textSize="16dp"
android:hint="Digite seu nome"/>
<TextView
android:id="@+id/textCadastroEstado"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginTop="10dp"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_estado"
android:visibility="visible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginLeft="-3dp"
android:layout_marginRight="-3dp"
android:gravity="top|left">
<Spinner
android:id="@+id/spinnerCadastroEstado"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="@+id/tvInvisibleEstado"
android:layout_width="2dp"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:layout_alignRight="@+id/spinnerCadastroEstado"
android:paddingTop="0dp"
android:paddingRight="27dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#8C8C8C"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"/>
</LinearLayout>
<TextView
android:id="@+id/textCadastroCidade"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginTop="19dp"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_cidade"
android:visibility="visible" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginLeft="-3dp"
android:layout_marginRight="-3dp">
<Spinner
android:id="@+id/spinnerCadastroCidade"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="@+id/tvInvisibleCidade"
android:layout_width="2dp"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:layout_alignRight="@+id/spinnerCadastroCidade"
android:paddingTop="0dp"
android:paddingRight="27dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#8C8C8C"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"/>
</LinearLayout>
<TextView
android:id="@+id/textCadastroEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginTop="19dp"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_email"
android:visibility="visible"/>
<EditText
android:id="@+id/editCadastroEmail"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:singleLine="true"
android:textSize="16dp"
android:hint="Digite seu e-mail"
android:inputType="textEmailAddress"
android:visibility="visible"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/llTelefones"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:background="@drawable/fundocomsombra"
android:gravity="center_horizontal"
android:id="@+id/llTelefoneAdd">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/addTelefone"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="8">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_add"
android:gravity="left"/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Adicionar telefone"
android:layout_weight="1"
android:layout_marginTop="7dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/fundocomsombra"
android:gravity="center_horizontal" >
<!-- label e input -->
<TextView
android:id="@+id/textCadastroTipoVeiculo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_tipoveiculo"
android:visibility="visible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginLeft="-3dp"
android:layout_marginRight="-3dp"
android:gravity="top|left">
<Spinner
android:id="@+id/spinnerCadastroTipoVeiculo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="@+id/tvInvisibleTipo"
android:layout_width="2dp"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:layout_alignRight="@+id/spinnerCadastroTipoVeiculo"
android:paddingTop="0dp"
android:paddingRight="27dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#8C8C8C"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"/>
</LinearLayout>
<TextView
android:id="@+id/textCadastroCarroceria"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginTop="19dp"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_carroceria"
android:visibility="visible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginLeft="-3dp"
android:layout_marginRight="-3dp"
android:gravity="top|left">
<Spinner
android:id="@+id/spinnerCadastroCarroceria"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="@+id/tvInvisibleCarroceria"
android:layout_width="2dp"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:layout_alignRight="@+id/spinnerCadastroCarroceria"
android:paddingTop="0dp"
android:paddingRight="27dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#8C8C8C"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"/>
</LinearLayout>
<TextView
android:id="@+id/textCadastroRastreador"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginTop="19dp"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_rastreador"
android:visibility="visible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginLeft="-3dp"
android:layout_marginRight="-3dp"
android:gravity="top|left">
<Spinner
android:id="@+id/spinnerCadastroRastreador"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="@+id/tvInvisibleRastreador"
android:layout_width="2dp"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:layout_alignRight="@+id/spinnerCadastroRastreador"
android:paddingTop="0dp"
android:paddingRight="27dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#8C8C8C"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"/>
</LinearLayout>
<TextView
android:id="@+id/textCadastroMarca"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginTop="19dp"
android:layout_marginLeft="3dp"
android:text="MARCA"
android:visibility="visible" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginLeft="-3dp"
android:layout_marginRight="-3dp"
android:gravity="top|left">
<Spinner
android:id="@+id/spinnerCadastroMarca"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<TextView
android:id="@+id/tvInvisibleMarca"
android:layout_width="2dp"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:layout_alignRight="@+id/spinnerCadastroMarca"
android:paddingTop="0dp"
android:paddingRight="27dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#8C8C8C"
android:layout_marginLeft="4dp"
android:layout_marginRight="2dp"/>
</LinearLayout>
<TextView
android:id="@+id/textCadastroSenha1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginTop="19dp"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_senha1"
android:visibility="visible" />
<EditText
android:id="@+id/editCadastroSenha1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:inputType="textPassword"
android:singleLine="true"
android:hint="Digite sua senha"
android:textSize="@dimen/size16"
android:fontFamily="@string/abc_search_hint" />
<TextView
android:id="@+id/textCadastroSenha2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/size12"
android:textColor="@color/colorTextGrayForte"
android:layout_marginTop="10dp"
android:layout_marginLeft="3dp"
android:text="@string/cadastro_senha2"
android:visibility="visible" />
<EditText
android:id="@+id/editCadastroSenha2"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:inputType="textPassword"
android:singleLine="true"
android:hint="Repita sua senha"
android:textSize="@dimen/size16"
android:fontFamily="@string/abc_search_hint" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/btCadastrar"
android:layout_below="@+id/editCadastroSenha2"
android:paddingTop="11dp"
android:paddingBottom="11dp"
android:background="@layout/fundoverdepressed"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:visibility="visible">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cadastro_btn"
android:gravity="center"
android:textColor="@android:color/white"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
UPDATE
Guys, I couldn’t solve it efficiently, but I thought of a way that worked well.
As I had a Scrollview, so I thought to put an event in the element to pick up when the user scrolls the screen, so if the user scrolls, then I Seto null for all setErrors(), then the error message disappears, not causing the overwriting problem Actionbar. The bad news is that the message will only appear again if the user tries to submit the form with the invalid fields again.
((ScrollView) findViewById(R.id.svGeral)).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Pra nao ficar entrando aqui sempre que rolar o scroll
if (errorEnabled) {
errorEnabled = false;
campoNome.setError(null);
campoEmail.setError(null);
campoSenha1.setError(null);
campoSenha2.setError(null);
// Remove alertas telefones
for (int et = 0; et < telefones.size(); et++) {
telefones.get(et).getEtTelefone().setError(null);
telefones.get(et).getTvInvisibleTipoTelefone().setError(null);
telefones.get(et).getTvInvisibleOperadoraTelefone().setError(null);
}
}
return false;
}
});
If someone has a better way to solve this problem, put us a look.
Thanks!
Could you put your xml layout? You’re using
Toolbar
? In which version this error happens?– Wakim
@Wakim I am not using Toolbar no. The version I am using for testing is 4.0. And about the layout, it does not influence this issue, because it has nothing different. I searched, and noticed that some people also have this problem. I updated with my xml.
– thalissonestrela