Java 按钮不工作,请单击
我有一个编写SQLite数据库的程序和一个读取数据库的视图按钮。每当我点击查看按钮,它不会做任何事情,我甚至不会收到任何错误或警告。我不知道我错过了什么。谁能帮帮我吗。我肯定我错过了一些很小的东西,但我不知道是什么Java 按钮不工作,请单击,java,android,eclipse,sqlite,Java,Android,Eclipse,Sqlite,我有一个编写SQLite数据库的程序和一个读取数据库的视图按钮。每当我点击查看按钮,它不会做任何事情,我甚至不会收到任何错误或警告。我不知道我错过了什么。谁能帮帮我吗。我肯定我错过了一些很小的东西,但我不知道是什么 package com.newboston.thefirst; import android.app.Activity; import android.app.Dialog; import android.content.Inte
package com.newboston.thefirst;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.database.sqlite.SQLiteException;
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 SQLiteExample extends Activity implements OnClickListener{
Button sqlUpdate, sqlView;
EditText sqlName, sqlFriend;
boolean worked;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sqliteexample);
sqlUpdate = (Button) findViewById(R.id.bsqlUpdate);
sqlView = (Button) findViewById(R.id.bsqlview);
sqlName = (EditText) findViewById (R.id.etsqlName);
sqlFriend = (EditText) findViewById(R.id.etsqlfrnd);
sqlUpdate.setOnClickListener(this);
sqlName.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.bsqlUpdate:
try {
String name = sqlName.getText().toString();
String frnd = sqlFriend.getText().toString();
Friendliness entry = new Friendliness (SQLiteExample.this);
entry.open();
entry.createEntry(name, frnd);
entry.Close();
worked = true;
} catch (SQLiteException e) {
worked= false;
} finally {
if (worked){
Dialog d = new Dialog(this);
d.setTitle("success!");
TextView tv = new TextView(this);
tv.setText("done!");
d.setContentView(tv);
d.show();
}
}
break;
case R.id.bsqlview:
sqlView.setText("done");
Intent i = new Intent ("com.newboston.thefirst.SQLView");
startActivity(i);
break;
}
}
}
我的xml代码是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="@+id/etsqlName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Friendliness" />
<EditText
android:id="@+id/etsqlfrnd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/bsqlUpdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update SQLite Database" />
<Button
android:id="@+id/bsqlview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View" />
</LinearLayout>
如果您需要任何其他代码,请告诉我。您忘记设置onClickListener。将此添加到SQLiteExample类的onCreate方法中
sqlView.setOnClickListener(this);
有没有可以发布的崩溃日志?它不会崩溃,也不会给我错误。我只是缺少正确变量的onClickListener。谢谢你的回复。它现在起作用了,非常好。。!!我使用了错误的变量。。!!现在很好用。。非常感谢。
sqlView.setOnClickListener(this);