public class MainActivity extends Activity {
EditText userid;
EditText passwd;
Button login;
TextView text;
Handler handler = new Handler();
String result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userid = (EditText) findViewById(R.id.userid);
passwd = (EditText) findViewById(R.id.passwd);
login = (Button) findViewById(R.id.login);
text = (TextView) findViewById(R.id.text);
// 버튼 이벤트 처리
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(1);
String userid1 = userid.getText().toString();
String passwd1 = passwd.getText().toString();
// 서버에 넘겨줄 파라미터 저장
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("userid1", userid1));
list.add(new BasicNameValuePair("passwd1", passwd1));
final String urlPath = "http://URL주소/xml/xmlApp.php?userid="
+ userid1 + "&passwd=" + passwd1;
// 네트워크 연동을 위한 작업 스레드 생성
Thread t = new Thread(new Runnable() {
@Override
public void run() {
InputStream is = requestGet(urlPath);
result = streamToString(is);
final int a = Integer.parseInt(result);
handler.post(new Runnable() {
@Override
public void run() {
if (a == 1) {
text.setText("로그인 성공");
} else {
text.setText("로그인 실패");
}
removeDialog(1);
}
});
}
});
t.start();
}
});
} // end onCreate
// Get 요청처리 메소드
public InputStream requestGet(String requestUrl) {
try {
// 요청하기
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(requestUrl);
HttpResponse response = client.execute(request);
// 응답하기
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
return is;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}// end requestGet
//
public String streamToString(InputStream is) {
StringBuffer buffer = new StringBuffer();
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is));
String str = reader.readLine();
while (str != null) {
buffer.append(str);
str = reader.readLine();
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
return buffer.toString();
}// end streamToString
@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;
}
}
다음과 같이 앱에서 웹으로 호출하여 디비에 저장된 아이디로 로그인을 하는것을 구현 하였습니다.
여기서 로그인 성공시 텍스트뷰에 로그인 성공이라는 텍스트가 나오는것이 아닌
디비에 저장된 계정의 이름과 나이를 불러오게 하고싶은데요 어떻게 구현해야 할까요?