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;
}
}
}
似乎第一种情况有效并且按钮更改了显示文本视图,但其余按钮不起作用。点击后没有任何事情发生但也没有错误。
任何人都知道为什么会这样吗?
干杯
答案 0 :(得分:0)
您没有在所有按钮上设置onClickListeners。
只有这两个:
submit.setOnClickListener(this);
etRowInfo.setOnClickListener(this);
添加以下内容:
bEdit.setOnClickListener(this);
bDelete.setOnClickListener(this);
bGetInfo.setOnClickListener(this);
答案 1 :(得分: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;
}
}}