To get the result set in label your code should look like this :
public static String verifyLogin(String UserName,String Password)
{
try
{
System.out.println("guru");
DefaultHttpClient httpClient=new DefaultHttpClient();
//Connect to the server
HttpGet httpGet=new HttpGet("http://xxxx/Service1.svc/checkLogin?name="+UserName+"&pass="+Password);
//Get the response
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream stream=httpEntity.getContent();
//Convert the stream to readable format
String result= convertStreamToString(stream);
}
catch(Exception e)
{
e.printStackTrace();
}
return result;
}
call above method like this in onclick:
String userName=txtUserName.getText().toString();
String password=txtPassword.getText().toString();
String res=verifyLogin(userName,password)
lblStatus.setText(res);
whatever result is will be displayed in textview.
WCF With Android- Binding result with labe or list view
Вопрос
- I have created a WCF which take 2 parameter username and password.
- I have created an android UI which take input username and password and on button click event it user name and password exist I have assigned a static value "Login successfully" to label.
I need guidance how can i bind the result set with label instead of passing static value to label.
public class JSONSampleAppActivity extends Activity implements OnClickListener{ /** Called when the activity is first created. */
//Property declaration
Button btnLogin;
TextView lblStatus;
EditText txtUserName,txtPassword;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnLogin=(Button)findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(this);
lblStatus=(TextView)findViewById(R.id.lblStatus);
txtUserName=(EditText)findViewById(R.id.txtUserName);
txtPassword=(EditText)findViewById(R.id.txtPassword);
}
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.btnLogin:
String userName=txtUserName.getText().toString();
String password=txtPassword.getText().toString();
if(verifyLogin(userName,password))
{
lblStatus.setText("Login Successfully");
}
else
{
lblStatus.setText("Login Failed");
}
break;
}
}
public static String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
public static boolean verifyLogin(String UserName,String Password)
{
try
{
System.out.println("guru");
DefaultHttpClient httpClient=new DefaultHttpClient();
//Connect to the server
HttpGet httpGet=new HttpGet("http://xxxx/Service1.svc/checkLogin?name="+UserName+"&pass="+Password);
//Get the response
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream stream=httpEntity.getContent();
//Convert the stream to readable format
String result= convertStreamToString(stream);
if(result.charAt(1)=='1')
{
return true;
}
else
{
return false;
}
}
catch(Exception e)
{
return false;
}
}
Решение
Не связан с StackOverflow