0% found this document useful (0 votes)
42 views4 pages

@override: Ajout Recher

The document contains code for an Android app with three activities - MainActivity, Ajout, and search. MainActivity contains buttons to launch the other activities. The Ajout activity allows adding a product by inputting details into edit texts and sending a POST request on button click. The search activity allows searching by inputting a key and sending a POST request on button click.

Uploaded by

Fraj Hariz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

@override: Ajout Recher

The document contains code for an Android app with three activities - MainActivity, Ajout, and search. MainActivity contains buttons to launch the other activities. The Ajout activity allows adding a product by inputting details into edit texts and sending a POST request on button click. The search activity allows searching by inputting a key and sending a POST request on button click.

Uploaded by

Fraj Hariz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

public class MainActivity extends AppCompatActivity {

Button ajout,recher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ajout = (Button) findViewById(R.id.a);
recher=(Button) findViewById(R.id.r);
ajout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i= new Intent(MainActivity.this,Ajout.class);
startActivity(i);
}
});
recher.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i= new Intent(MainActivity.this,search.class);
startActivity(i);
}
});
}
}
public class Ajout extends AppCompatActivity {
EditText r, n, p, q;
Button ok;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ajout);
r=(EditText) findViewById(R.id.editText);
n=(EditText) findViewById(R.id.editText2);
p=(EditText) findViewById(R.id.editText3);
q=(EditText) findViewById(R.id.editText4);
ok= (Button) findViewById(R.id.button);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String ref=r.getText().toString();
final String name=n.getText().toString();
final String price=p.getText().toString();
final String quant=q.getText().toString();
StringRequest sr= new StringRequest(Request.Method.POST,
"http://192.168.2.92/gestion/ajout.php", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject js = new JSONObject(response);
String n=js.getString("etat");
if (n.equals("ok"))
{
Toast.makeText(Ajout.this, "Produit ajoute
avec succes", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(Ajout.this,"erreur
!",Toast.LENGTH_LONG).show();
}
} catch (Exception e)
{

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
}) {
protected Map<String,String> getparams() throws
AuthFailureError{
HashMap<String,String> po=new HashMap<String,
String>();
po.put("ref",ref);
po.put("nom",name);
po.put("prix",price);
po.put("quantite",quant);
return po;
}
};
RequestQueue rq= Volley.newRequestQueue(Ajout.this);
rq.add(sr);
}
});
}

}
public class search extends AppCompatActivity {
Button b;
EditText T;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
b=(Button) findViewById(R.id.button2);
T=(EditText) findViewById(R.id.editText5);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String cle=T.getText().toString();
StringRequest sr= new StringRequest(Request.Method.POST,
"http://192.168.2.92/gestion/search.php", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject js = new JSONObject(response);
String n=js.getString("produits");

//// TODO: 26/10/2017

} catch (Exception e)
{

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
}) {
protected Map<String,String> getparams() throws
AuthFailureError {
HashMap<String,String> po=new HashMap<String,
String>();
po.put("cle",cle);

return po;
}
};
RequestQueue rq= Volley.newRequestQueue(search.this);
rq.add(sr);
}
});
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy