主な活動このコードにはログイン画面とデータ入力画面があり、機能していましたが、
現在は機能せず、エラーも発生しません。これは以前に修正しましたが、覚えています
package com.Trish.diabetesapp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.R;
public class MainActivity extends Activity {
EditText txtUserName;
EditText txtPassword;
Button btnLogin;
Button btnCancel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtUserName=(EditText)this.findViewById(R.id.txtUname);
txtPassword=(EditText)this.findViewById(R.id.txtPwd);
btnLogin=(Button)this.findViewById(R.id.btnLogin);
btnLogin=(Button)this.findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = null;
if((txtUserName.getText().toString()).equals("dom") && (txtPassword.getText().toString().equals("trisha"))){
//Toast.makeText(Login.this, "Login Successful",Toast.LENGTH_LONG).show();
myIntent = new Intent(v.getContext(), Login.class);
}else{
Toast.makeText(MainActivity.this, "Invalid Login",Toast.LENGTH_LONG).show();
}
startActivity(myIntent);
}
});
}
//@Override
//public boolean (Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.login, menu);
// return true;
//}
}
ログイン画面パッケージ com.Trish.diabetesapp は次のとおりです。android.os.Bundle をインポートします。
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.R;
import android.os.StrictMode;
import android.util.Log;
import android.widget.EditText;
public class Login extends Activity {
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
EditText breakfast= (EditText) findViewById(R.id.breakfast) ;
EditText lunch = (EditText) findViewById(R.id.lunch);
EditText dinner = (EditText) findViewById(R.id.dinner);
EditText supper = (EditText) findViewById(R.id.supper);
Button button = (Button) findViewById(R.id.button1) ;
final String breakf = breakfast.getText().toString();
final String lun = lunch.getText().toString();
final String din = dinner.getText().toString();
final String sup = supper.getText().toString();
button2=(Button)this.findViewById(R.id.button2);
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// generate your params:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("breakfast", breakf));
nameValuePairs.add(new BasicNameValuePair("Lunch", lun));
nameValuePairs.add(new BasicNameValuePair("Dinner", din));
nameValuePairs.add(new BasicNameValuePair("supper", sup));
// send them on their way
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://xyz/register.php");
//httpPost.setEntity(new UrlEncodedFormEntity(nameValueParams));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}});}
//@Override
//public void onClick(View v) {
//finish();
//System.exit(0);
//}
//});
//Intent intent = new Intent(Login.this, .class);
//Login.this.startActivity(intent);
//new lister for save start db code their
//take info from button with sql
// @Override
// public void onClick(View arg0) {
// TODO Auto-generated method stub
//postData();
//});
//
//}
@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;
}
ここにxmlがあります
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.Trish.diabetesapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.Trish.diabetesapp.Login"
android:label="@string/title_activity_login" >
</activity>
</application>
</manifest>