apm이랑 이클립스로 인터넷에 나온 예제 보고 만들었는데요
회원가입없이 mysql에 있는 테이블에 직접 아이디랑 비밀번호 넣고 안드로이드 로그인 화면에서 로그인하면
데이터를 찾아서 성공시키는 것을 하려고 하는데
로그인버튼을 막상 누르면 로딩만 되고 데이터를 못불러오는것 같더라구요 뭐가 문제인지 모르겠어서 질문드려요
안드로이드 완전 생초보 입니다 ㅜㅜ
main.java
public class MainActivity extends Activity{
ViewFlipper vf; //웹뷰로드
Button Btnlogin;
EditText inputID, inputPW;
HttpPost httppost;
HttpResponse response;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
ProgressDialog dialog = null;
//LinearLayout layout01;
//private static final String SERVER_ADDRESS = "http://내아이피:8080";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy Policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(Policy);
Btnlogin = (Button)findViewById(R.id.login);
inputID = (EditText)findViewById(R.id.idlogin);
inputPW = (EditText)findViewById(R.id.pwlogin);
Btnlogin.setOnClickListener(new OnClickListener(){
public void onClick(View v){
dialog = ProgressDialog.show(MainActivity.this,"","validating user...",true);
new Thread(new Runnable(){
public void run(){
Looper.prepare();
login();
Looper.loop();
}
}).start();
}
});
}
void login(){
try{
httpclient=new DefaultHttpClient();
httppost=new HttpPost("http://내아이피:8080/logcheck.php");
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id",inputID.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("password",inputPW.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response :" + response);
runOnUiThread(new Runnable(){
public void run(){
dialog.dismiss();
}
});
if(response.equalsIgnoreCase("user Found")){
runOnUiThread(new Runnable(){
public void run(){
Toast.makeText(MainActivity.this,"login Success",Toast.LENGTH_SHORT).show();
}
});
//layout01.setBackgroundColor(Color.GREEN);
//startActivity(new Intent(MainActivity.this,TapView.class));
finish();
}else{
//layout01.setBackgroundColor(Color.RED);
Toast.makeText(MainActivity.this,"Login Fail",Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
dialog.dismiss();
System.out.println("Exception:" + e.getMessage());
}
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
php
<?php
$hostname_localhost = "127.0.0.1:3306";
$database_localhost = "swumap";
$username_localhost = "root";
$password_localhost = "";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_localhost,$localhost);
$id=$_POST['id'];
$password=$_POST['password'];
$query_search="select * from login where id = '".$id."'AND password='".$password."'";
$query_exec = mysql_qury($query_search) or die(mysql_error());
$rows = mysql_num_rows($quert_exec);
if($row ==0){
echo "no such user found";
}
else{
echo "user found";
}
?>