在可以输入所有数据之前,Secondary Activity 进入 Main Activity [英] Secondary Activity goes the Main Activity before all the data can be input

查看:9
本文介绍了在可以输入所有数据之前,Secondary Activity 进入 Main Activity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个来查看、编辑和创建联系人.当我在模拟器中运行代码时,它允许我输入名称,但我无法切换到其他编辑文本并且模拟器冻结.即使我切换,我唯一能做的就是按下后退按钮.这是我的代码,你能帮我调试一下吗?我是android编程新手,欢迎所有建议.

I have written an to view , edit and create contacts . When I run the code in emulator , it allows me to type the name but I cannot switch to other Edit Text and the emulator freezes.Even if I switch, the only thing I can do is press back button after. here is my code , could you please help me in debugging. I am new to android programming , all suggestions are welcome.

public class AddNewContact extends Activity implements OnClickListener {
    Button Save;
    EditText Newname, NewPersonalPhone, NewHomePhone, NewOfficePhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newcontact);
        initialize();
    }

    private void initialize() {
        // TODO Auto-generated method stub
        Save = (Button) findViewById(R.id.bSaveContact);
        Save.setOnClickListener(this);
        Newname = (EditText) findViewById(R.id.newname);
        Newname.setOnClickListener(this);
        NewPersonalPhone = (EditText) findViewById(R.id.newpersonalphone);
        NewPersonalPhone.setOnClickListener(this);
        NewHomePhone = (EditText) findViewById(R.id.newhomephone);
        NewHomePhone.setOnClickListener(this);
        NewOfficePhone = (EditText) findViewById(R.id.newofficephone);
        NewOfficePhone.setOnClickListener(this);

    }

    public void onClick(View v) {
        boolean didItWork = true;
        // TODO Auto-generated method stub
        try {
            String nname = Newname.getText().toString();
            String npphone = NewPersonalPhone.getText().toString();
            String nhphone = NewHomePhone.getText().toString();
            String nophone = NewOfficePhone.getText().toString();


            DBContact newentry = new DBContact(AddNewContact.this);
            newentry.open();
            newentry.newRow(nname, npphone, nhphone, nophone);
            newentry.close();

        } catch (Exception e) {
            didItWork = false;
            String error = e.toString();
            Dialog display = new Dialog(this);
            display.setTitle("ERROR");
            TextView text = new TextView(this);
            text.setText(error);
            display.setContentView(text);
            display.show();
        } finally {
            if (didItWork) {
                Dialog display = new Dialog(this);
                display.setTitle("CONTACT SAVED!");
                TextView text = new TextView(this);
                text.setText("Sucess");
                display.setContentView(text);
                display.show();
            //  startActivity(new Intent("CONTACTS.class"));
            }
        }
    }

}

LOGCAT

09-26 02:58:35.518: E/WindowManager(1913): Activity com.example.contactlist.AddNewContact has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41236e28 that was originally added here
09-26 02:58:35.518: E/WindowManager(1913): android.view.WindowLeaked: Activity com.example.contactlist.AddNewContact has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41236e28 that was originally added here
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:374)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.Window$LocalWindowManager.addView(Window.java:547)
09-26 02:58:35.518: E/WindowManager(1913):  at android.app.Dialog.show(Dialog.java:277)
09-26 02:58:35.518: E/WindowManager(1913):  at com.example.contactlist.AddNewContact.onClick(AddNewContact.java:56)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.View.performClick(View.java:4084)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.View.onKeyUp(View.java:7669)
09-26 02:58:35.518: E/WindowManager(1913):  at android.widget.TextView.onKeyUp(TextView.java:5382)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.KeyEvent.dispatch(KeyEvent.java:2633)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.View.dispatchKeyEvent(View.java:7086)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
09-26 02:58:35.518: E/WindowManager(1913):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1892)
09-26 02:58:35.518: E/WindowManager(1913):  at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1369)
09-26 02:58:35.518: E/WindowManager(1913):  at android.app.Activity.dispatchKeyEvent(Activity.java:2356)
09-26 02:58:35.518: E/WindowManager(1913):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1819)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3575)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewRootImpl.deliverKeyEvent(ViewRootImpl.java:3531)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3113)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
09-26 02:58:35.518: E/WindowManager(1913):  at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2930)
09-26 02:58:35.518: E/WindowManager(1913):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 02:58:35.518: E/WindowManager(1913):  at android.os.Looper.loop(Looper.java:137)
09-26 02:58:35.518: E/WindowManager(1913):  at android.app.ActivityThread.main(ActivityThread.java:4745)
09-26 02:58:35.518: E/WindowManager(1913):  at java.lang.reflect.Method.invokeNative(Native Method)
09-26 02:58:35.518: E/WindowManager(1913):  at java.lang.reflect.Method.invoke(Method.java:511)
09-26 02:58:35.518: E/WindowManager(1913):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-26 02:58:35.518: E/WindowManager(1913):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-26 02:58:35.518: E/WindowManager(1913):  at dalvik.system.NativeStart.main(Native Method)

推荐答案

你需要吗setOnClickListener()

即使是编辑文本?

你为什么要在编辑文本上使用 setOnClickListener().这有什么特别的原因吗?

why are you trying to use setOnClickListener() on edittexts. Is there any special reason for this?

一旦尝试删除它们,只需使用 setOnClickListener() 作为按钮并运行逻辑.如果您有任何特殊原因使用 setOnClickListener() 进行编辑文本,请解释一次

once try to remove them and just use setOnClickListener() for button and run the logic. If you have any special reason for using setOnClickListener() for edittext explain it once

这篇关于在可以输入所有数据之前,Secondary Activity 进入 Main Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆