-1
            package com.gofitness.www;

            import android.app.Activity;


            import android.os.Bundle
            import android.view.View;
            import android.view.View.OnClickListener;
            import android.widget.Button;
            import android.widget.EditText;
            import android.widget.TextView;


            public class log extends Activity implements OnClickListener {

    Button submit,bEdit, bGetInfo, bDelete;
    TextView display;
    EditText etRowInfo, username, password;




    protected void onCreate(Bundle login) {
            // TODO Auto-generated method stub
            super.onCreate(login);
    setContentView(R.layout.insert);

     submit = (Button) findViewById(R.id.submit);
    username = (EditText) findViewById(R.id.etUsername);
    password = (EditText) findViewById(R.id.etPassword);
  display = (TextView) findViewById(R.id.tvDisplay);
 bEdit = (Button) findViewById(R.id.bEdit);
 etRowInfo  = (EditText) findViewById(R.id.etRowInfo);
 bGetInfo = (Button) findViewById(R.id.bGetInfo);
 bDelete = (Button) findViewById(R.id.bDelete);

  submit.setOnClickListener(this);
  etRowInfo.setOnClickListener(this);
    }
            public void onClick(View arg0) {
                    switch (arg0.getId()){
                    case R.id.submit:
                            display.setText("fdf");
                    boolean didItWork = true;

                    try{
                    String check = username.getText().toString();
                    String checkpass = password.getText().toString();

                    logindetails entry = new logindetails(log.this);
                    entry.open();
                    entry.createEntry(check, checkpass);
                    entry.close();


                    }catch (Exception e){
                    didItWork = false;
                    String error = e.toString();
                    display.setText(error);
                    }finally{
                    if (didItWork){

                    display.setText("WERKED");
                    }
                    }





                    break; 
                    case R.id.bGetInfo:
                            display.setText("fdf");
                            String s = etRowInfo.getText().toString();
                            long l = Long.parseLong(s);
                            logindetails log = new logindetails(this);
                            log.open();
                            String returnedName = log.getName(l);
                            String returnedPassword = log.getPassword(l);
                            log.close();

                            password.setText(returnedPassword);

                            break;


                    case R.id.bEdit:
                            display.setText("fdf");


                            break;



                    case R.id.bDelete:
                            display.setText("fdf");


                            break;



            }





    }
    } 

似乎第一种情况有效,并且按钮更改了显示文本视图,但是其余按钮不起作用。单击后没有任何反应,但也没有错误。

有谁知道为什么会这样?

干杯

4

2 回答 2

0

您缺少在 onClick 方法之前编写@override,因为它是接口,因此我们需要编写它或从下面的代码中获取帮助

 import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;

        public class MainActivity extends Activity implements OnClickListener {
        Button b1,b2;
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                b1=(Button)findViewById(R.id.button1);

                b2=(Button)findViewById(R.id.button2);
                b1.setOnClickListener(this);
                b2.setOnClickListener(this);
            }



            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                 int id=v.getId();
                 switch(id) {
                    case R.id.button1:
                  Toast.makeText(getBaseContext(), "btn1", Toast.LENGTH_LONG).show();
                //Your Operation

                  break;

                    case R.id.button2:
                          Toast.makeText(getBaseContext(), "btn2", Toast.LENGTH_LONG).show();


                          //Your Operation
                          break;
            }

        }}
于 2014-09-01T08:00:14.003 回答
0

您没有在所有按钮上设置 onClickListeners。

只有这两个:

submit.setOnClickListener(this);
etRowInfo.setOnClickListener(this);

添加这些:

bEdit.setOnClickListener(this);
bDelete.setOnClickListener(this);
bGetInfo.setOnClickListener(this);
于 2013-04-27T15:42:39.903 回答