我用 EditTexts 和 textview 制作了一个具有相同布局的应用程序,我在底部发布了来自 xml 的代码,如果我尝试在其中写一些东西,它工作正常,但是如果多次单击一个编辑文本,应用程序崩溃,这就是 logcat
03-18 12:09:43.007: E/AndroidRuntime(13064): FATAL EXCEPTION: main
03-18 12:09:43.007: E/AndroidRuntime(13064): java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_height="wrap_content"
03-18 12:09:43.007: E/AndroidRuntime(13064): at com.android.internal.widget.ActionBarContextView.onMeasure(ActionBarContextView.java:426)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1385)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.LinearLayout.measureVertical(LinearLayout.java:670)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.LinearLayout.onMeasure(LinearLayout.java:563)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-18 12:09:43.007: E/AndroidRuntime(13064): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2261)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1385)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.LinearLayout.measureVertical(LinearLayout.java:670)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.LinearLayout.onMeasure(LinearLayout.java:563)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1399)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.ScrollView.onMeasure(ScrollView.java:367)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
03-18 12:09:43.007: E/AndroidRuntime(13064): at
android.view.View.measure(View.java:12922)
03-18 12:09:43.007: E/AndroidRuntime(13064): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
03-18 12:09:43.007: E/AndroidRuntime(13064): at
这是xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="5dp" >
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0dip"
android:layout_height="0dip"/>
<TextView
android:id="@+id/textNume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="NUME SI PRENUME"
android:textColor="@color/MenuDarkGrey"
android:textSize="13sp" />
<EditText
android:id="@+id/edtNume"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="@drawable/edit_text"
android:gravity="left"
android:inputType="textCapWords"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="@color/ColorTitlu"
android:textSize="18sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_margin="1dp"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textCNP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CNP"
android:textColor="@color/MenuDarkGrey"
android:textSize="13sp" />
<ImageView
android:id="@+id/wrong_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:visibility="gone"
android:layout_alignParentTop="true"
android:src="@drawable/exclamare_atentionare" />
</RelativeLayout>
<EditText
android:id="@+id/edtCNP"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="@drawable/edit_text"
android:ems="10"
android:gravity="left"
android:inputType="number|textCapWords"
android:maxLength="25"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="@color/ColorTitlu"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textJudLoc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="JUDET,LOCALITATE"
android:textColor="@color/MenuDarkGrey"
android:textSize="13sp" />
<EditText
android:id="@+id/edtJudLoc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="@drawable/edit_text"
android:focusableInTouchMode="false"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="@color/ColorTitlu"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textAdresa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="ADRESA"
android:textColor="@color/MenuDarkGrey"
android:textSize="13sp" />
<EditText
android:id="@+id/edtAdresa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="@drawable/edit_text"
android:gravity="left"
android:inputType="textCapWords"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="@color/ColorTitlu"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textTelefon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="TELEFON"
android:textColor="@color/MenuDarkGrey"
android:textSize="13sp" />
<EditText
android:id="@+id/edtTelefon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="@drawable/edit_text"
android:gravity="left"
android:inputType="number|textCapWords"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="@color/ColorTitlu"
android:textSize="18sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_margin="1dp"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:gravity="left"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="EMAIL"
android:textColor="@color/MenuDarkGrey"
android:textSize="13sp" />
<ImageView
android:id="@+id/wrong_textmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:visibility="gone"
android:layout_alignParentTop="true"
android:src="@drawable/exclamare_atentionare" />
</RelativeLayout>
<EditText
android:id="@+id/edtEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:background="@drawable/edit_text"
android:gravity="left"
android:lines="1"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:textColor="@color/ColorTitlu"
android:textSize="18sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp" >
<Button
android:id="@+id/renunta"
android:layout_width="140dp"
android:layout_height="50dp"
android:background="@drawable/button_renunta"
android:paddingLeft="40dp"
android:text="Renunta"
android:textColor="@color/MenuLightGrey"
android:textSize="16sp"
android:textStyle="bold" >
</Button>
<Button
android:id="@+id/salveaza"
android:layout_width="140dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/button_salveaza"
android:paddingLeft="40dp"
android:text="Salveaza"
android:textColor="@color/MenuLightGrey"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
和课堂上的代码
edtNume = (EditText)findViewById (R.id.edtNume);
edtNume.setOnFocusChangeListener(new OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus == true)
{
ContulMeu.tooltip.setVisibility (View.VISIBLE);
ContulMeu.tvTooltip.setText ("Completeaza numele si prenumele");
}else{
ContulMeu.tvTooltip.setText ("");
ContulMeu.tooltip.setVisibility (View.GONE);
}
}
});
edtCnp = (EditText)findViewById (R.id.edtCNP);
edtCnp.setOnFocusChangeListener(new OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus == true)
{
ContulMeu.tooltip.setVisibility (View.VISIBLE);
ContulMeu.tvTooltip.setText ("Codul numeric personal");
}else{
ContulMeu.tvTooltip.setText ("");
ContulMeu.tooltip.setVisibility (View.GONE);
}
}
});
edtCnp.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
if (edtCnp.getText().toString().length()!=13 || !YTOUtils.verificaCNP(edtCnp.getText().toString()))
((ImageView) findViewById(R.id.wrong_text)).setVisibility(View.VISIBLE);
else ((ImageView) findViewById(R.id.wrong_text)).setVisibility(View.GONE);
}
});
edtJudLoc = (EditText)findViewById (R.id.edtJudLoc);
edtJudLoc.setOnClickListener (new OnClickListener()
{
@Override
public void onClick(View v)
{
if (edtCnp.getText().toString().length()!=13 || !YTOUtils.verificaCNP(edtCnp.getText().toString()))
((ImageView) findViewById(R.id.wrong_text)).setVisibility(View.VISIBLE);
else ((ImageView) findViewById(R.id.wrong_text)).setVisibility(View.GONE);
salveaza=false;//nu salvez cand trebuie setat judetul
Lista.tipDate = "judete";
Intent i = new Intent (DespreMine.this,Lista.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity (i);
}
});
edtJudLoc.setFocusable(false);
edtAdresa = (EditText)findViewById (R.id.edtAdresa);
edtAdresa.setOnFocusChangeListener(new OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus == true)
{
ContulMeu.tooltip.setVisibility (View.VISIBLE);
ContulMeu.tvTooltip.setText ("Adresa completa din buletin");
}else{
ContulMeu.tvTooltip.setText ("");
ContulMeu.tooltip.setVisibility (View.GONE);
}
}
});
edtTelefon = (EditText)findViewById (R.id.edtTelefon);
edtTelefon.setOnFocusChangeListener(new OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus == true)
{
ContulMeu.tooltip.setVisibility (View.VISIBLE);
ContulMeu.tvTooltip.setText ("Numarul tau de telefon la care poti fi contactat");
}else{
ContulMeu.tvTooltip.setText ("");
ContulMeu.tooltip.setVisibility (View.GONE);
}
}
});
edtEmail = (EditText)findViewById (R.id.edtEmail);
edtEmail.setOnFocusChangeListener(new OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus == true)
{
ContulMeu.tooltip.setVisibility (View.VISIBLE);
ContulMeu.tvTooltip.setText ("Adresa de e-mail la care poti fi contactat");
}else{
ContulMeu.tvTooltip.setText ("");
ContulMeu.tooltip.setVisibility (View.GONE);
edtEmail.setText(YTOUtils.replaceInEmail(edtEmail.getText().toString()));
}
}
});
edtEmail.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
if (!YTOUtils.eMailValidation(edtEmail.getText().toString()))
((ImageView) findViewById(R.id.wrong_textmail)).setVisibility(View.VISIBLE);
else ((ImageView) findViewById(R.id.wrong_textmail)).setVisibility(View.GONE);
}
});
load();
btn_renunta = (Button) findViewById (R.id.renunta);
btn_renunta.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
salveaza=false;
finish ();
}
});
btn_salveaza = (Button) findViewById (R.id.salveaza);
btn_salveaza.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
salveaza=false;//daca salveaza=true salvez si la onPause()
AsyncTask<Object, Object, Object> saveContactTask =
new AsyncTask<Object, Object, Object>()
{
@Override
protected Object doInBackground(Object... params)
{
saveContact();
return null;
}
@Override
protected void onPostExecute(Object result)
{
finish();
}
};
saveContactTask.execute((Object[]) null);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edtTelefon.getWindowToken(), 0);
}
});
Typeface tf = Typeface.createFromAsset(getAssets(), "ArialRoundedMT.ttf");
edtNume.setTypeface(Typeface.create(tf,Typeface.BOLD));
edtCnp.setTypeface(Typeface.create(tf,Typeface.BOLD));
edtJudLoc.setTypeface(Typeface.create(tf,Typeface.BOLD));
edtAdresa.setTypeface(Typeface.create(tf,Typeface.BOLD));
edtTelefon.setTypeface(Typeface.create(tf,Typeface.BOLD));
edtEmail.setTypeface(Typeface.create(tf,Typeface.BOLD));
}