Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $DB_USER='root';
- $DB_PASS='';
- $DB_HOST='localhost';
- $DB_NAME='pfe';
- $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
- /* check connection */
- if (mysqli_connect_errno())
- {
- printf("Connect failed: %sn", mysqli_connect_error());
- exit();
- }
- $comm = $_GET['comm'];
- $mysqli->query("SET NAMES 'utf8'");
- $sql="SELECT nomco FROM commune where idwi=".$comm;
- $result=$mysqli->query($sql);
- while($e=mysqli_fetch_assoc($result))
- {
- $output[]=$e;
- }
- print(json_encode($output));
- $mysqli->close();
- ?>
- public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
- EditText idtxt;
- TextView txtaffich;
- ArrayAdapter<String> listadapter;
- ListView listView;
- ArrayList<String> listcom = new ArrayList<>();
- HttpURLConnection httpURLConnection;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- idtxt = (EditText) findViewById(R.id.editTextId);
- listView = (ListView)findViewById(R.id.listView);
- listadapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listcom);
- listView.setAdapter(listadapter);
- listView.setOnItemClickListener(this);
- }
- public void send(View view) {
- String id = idtxt.getText().toString();
- if (id.length() == 0 ) {
- Toast.makeText(MainActivity.this, "Vous devez remplir les champs", Toast.LENGTH_LONG).show();
- }else {
- Toast.makeText(this, "wait...", Toast.LENGTH_SHORT).show();
- new SignupActivity().execute(id);
- Toast.makeText(this, id, Toast.LENGTH_SHORT).show();
- }
- }
- public class SignupActivity extends AsyncTask<String, Void, String> {
- ArrayList<String> me;
- protected void onPreExecute() {
- super.onPreExecute();
- me =new ArrayList<>();//pour lis
- }
- @Override
- protected String doInBackground(String... arg0) {
- String idenv = arg0[0];
- InputStream is=null;
- String link;
- String data;
- BufferedReader bufferedReader2;
- String result="";
- try {//le message a envoyer + mail
- //we append to this URL a ‘?’ mark and the variable values
- // separated by ‘&’ sign, these values will be passed to the server by HTTP GET method.
- data = "?comm=" + URLEncoder.encode(idenv, "UTF-8");
- link = "http://192.168.43.93/pfe/select_spinner_com.php" + data;
- URL url = new URL(link);
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
- is= con.getInputStream();
- bufferedReader2 = new BufferedReader(new InputStreamReader(is));
- String line2 = "";
- while ((line2 = bufferedReader2.readLine().toString()) != null) {
- result += line2;
- }
- } catch (Exception e) {
- return new String("Exception: " + e.getMessage());
- }
- try {
- JSONArray jsonArray = new JSONArray(result);
- for (int ii = 0; ii < jsonArray.length(); ii++) {
- JSONObject jsonObject2 = jsonArray.getJSONObject(ii);
- me.add(jsonObject2.getString("nomco"));
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
- protected void onPostExecute(String result) {
- listcom.addAll(me);//pour list view
- listadapter.notifyDataSetChanged(); }
- }
- }
- <uses_permission android:name="android.permission.INTERNET" />
- <uses_permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement