我想检查我的Android应用程序(加载到Android设备中)输入的变量是否存在于我的MySQL数据库中
这是我的代码
tav_enterstudentno.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/btn_enterstudentno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="74dp"
android:text="Enter Student No" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_enterstudentno"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:text="TextView" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity {
Button btn_enterstudentno;
TextView throwhere;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tav_enterstudentno);
tavinputswindow();
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void tavinputswindow()
{
setContentView(R.layout.tav_enterstudentno);
btn_enterstudentno = (Button)this.findViewById(R.id.btn_enterstudentno);
btn_enterstudentno.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0)
{
enterstudentno(); //POPS UP DIALOGBOX ASKING FOR STUDENT NO.
}
});
}
//POPS UP DIALOGBOX ASKING FOR STUDENT NO.
public void enterstudentno()
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Enter Student No."); //alert.setMessage("Message");
final EditText input = new EditText(this); // Set an EditText view to get user input
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() //FOR OK BUTTON
{
public void onClick(DialogInterface dialog, int whichButton)
{
String studentno = input.getText().toString();
//CHECK DATA BASE FOR EXISTENCE OF STUDENT ID NO *****
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener()//FOR CANCEL BUTTON
{
public void onClick(DialogInterface dialog, int whichButton)
{
dialog.cancel(); // Canceled.
}
});
alert.show();
}
}
这就是我想要发生的事情;当按下btn_enterstudentno时,会弹出一条警告消息,要求用户输入学生号码。如果在弹出警报消息中按下了确定按钮,并且用户已经在警报消息文本字段中输入了某些内容,程序将检查输入的学号是否是某个MySQl数据库中表的主键。 / p>
提前谢谢!