1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
package com.example.lakaj.depotage;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.example.yannick.webtendernews.MainActivity;
import com.example.yannick.webtendernews.R;
import java.util.List;
import static com.example.yannick.webtendernews.R.id;
import static com.example.yannick.webtendernews.R.layout;
/**
* Created by barre on 08/05/2014.
*/
public class AddclientActivity extends ActionBarActivity {
public final static String TAG = "ActionBarActivity";
private MenuItem itemAccueil;
//private MenuItem itemAjoutFluxRss;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout.activity_addclient);
final ClientBdd clientBdd = new ClientBdd(this);
/* ============================================
Gestion des données de la bdd
============================================ */
clientBdd.open();
// List<String> nomsCateg = categoriesBdd.getNoms();
final List<Client> clients = clientBdd.getClients();
clientBdd.close();
/* ============================================
Declaration des elements du layout
============================================= */
final TextView nomClient = (TextView) findViewById(id.txtNomClient);
final TextView typeClient = (TextView) findViewById(id.txtTypeClient);
Button btnAddClient = (Button) findViewById(id.btnAjout);
btnAddClient.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String msg = "";
String nom = nomClient.getText().toString();
String type = typeClient.getText().toString();
// Log.d(TAG, "nom saisi : " + nom + "description saisie : " + description);
if(nom.length() != 0 && typeClient.length() != 0){
Client newClient = new Client(nom, type);
// Log.d(TAG, "client à ajouter : " + newClient.toString());
if(newClient != null) {
clientBdd.open();
clientBdd.insertClient(newClient);
clientBdd.close();
msg = "client ajouté !";
}
else{
msg = "impossible d'ajouter un client";
}
}
else{
msg = "saisir tout les champs svp";
}
Toast.makeText(AddclientActivity.this, msg, Toast.LENGTH_SHORT).show(); // si pas erreur
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
itemAccueil = (MenuItem) findViewById(id.action_accueil);
itemAjoutClient = (MenuItem) findViewById(id.action_ajout_client);
itemAjoutFluxRss = (MenuItem) findViewById(id.action_ajout_fluxrss);
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.accueil, 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();
switch (id) {
case R.id.action_accueil:
//do something
Intent intentMain = new Intent(AddclientActivity.this, MainActivity.class);
startActivity(intentMain);
return true;
case R.id.action_ajout_fluxrss:
//do something
Intent intentAddClient = new Intent(AddclientActivity.this, AddClientActivity.class);
startActivity(intentAddClient);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
} |
Partager