title: Add ItemOnClick from my listview, fetching data using JSON from MYSQL
body: <p>I'm a beginner to android development.
  It may look very basic but i really getting a hard-time to make it work in my project.</p>
  
  <p>I am developing an application for professor to see all the student list who under probation in database.</p>
  
  <p>in my progress after they log in their account to the application, all the students who are in the database will show in <code>ListView</code> form</p>
  
  <p>here is my code for this activity</p>
  
  <p>UPDATE1:I Manage to make the items clickable and show new activity named Profile.class
  (i expect it to show
  student name: <em>show name</em>
  student id: <em>show id</em>
  but it showing NULL)</p>
  
  <p>Here is my update code</p>
  
  <pre><code>public class MainPage extends Activity {
  
  TextView name,email;
  private String jsonResult;
  private String url = "http://192.168.254.106/notificationapp/students.php";
  private ListView listView;
  String stud_name, stud_id;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.mainpage_layout);
      name = (TextView)findViewById(R.id.name);
      email = (TextView)findViewById(R.id.email);
      Bundle bundle = getIntent().getExtras();
      name.setText("Welcome "+bundle.getString("name"));
      email.setText("Email: "+bundle.getString("email"));
      listView = (ListView) findViewById(R.id.listView);
      accessWebService();
  }
  
  
  
  @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;
  }
  // Async Task to access the web
  private class JsonReadTask extends AsyncTask&lt;String, Void, String&gt; {
      @Override
      protected String doInBackground(String... params) {
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost(params[0]);
          try {
              HttpResponse response = httpclient.execute(httppost);
              jsonResult = inputStreamToString(
                      response.getEntity().getContent()).toString();
          }
  
          catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return null;
      }
      private StringBuilder inputStreamToString(InputStream is) {
          String rLine = "";
          StringBuilder answer = new StringBuilder();
          BufferedReader rd = new BufferedReader(new InputStreamReader(is));
  
          try {
              while ((rLine = rd.readLine()) != null) {
                  answer.append(rLine);
              }
          }
  
          catch (IOException e) {
              // e.printStackTrace();
              Toast.makeText(getApplicationContext(),
                      "Error..." + e.toString(), Toast.LENGTH_LONG).show();
          }
          return answer;
      }
  
      @Override
      protected void onPostExecute(String result) {
          ListDrawer();
      }
  }// end async task
  
  public void accessWebService() {
      JsonReadTask task = new JsonReadTask();
      task.execute(new String[] { url });
  }
  
  
  public void ListDrawer() {
      final List&lt;Map&lt;String, String&gt;&gt; studentList = new ArrayList&lt;Map&lt;String, String&gt;&gt;();
  
      try {
          JSONObject jsonResponse = new JSONObject(jsonResult);
          JSONArray jsonMainNode = jsonResponse.optJSONArray("student_info");
  
          for (int i = 0; i &lt; jsonMainNode.length(); i++) {
              JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
              String name = jsonChildNode.optString("student_name");
              String number = jsonChildNode.optString("student_id");
              String outPut = name + "-" + number;
              studentList.add(createStudent("Students", outPut));
          }
      } catch (JSONException e) {
          Toast.makeText(getApplicationContext(), "Error" + e.toString(),
                  Toast.LENGTH_SHORT).show();
      }
   ////////////////////////////////// UPDATE LISTVIEW ITEMS ONCLICK
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
               studentList.get(position);
              //Do your logic for getting the student variables here
              Intent intent = new Intent(MainPage.this,Profile.class);
              Bundle b = new Bundle();
              b.putString("student_name", stud_name);
              b.putString("student_id", stud_id);
              intent.putExtras(b);
              startActivity(intent);
          }
      });
  //////////////////////////////////////UPDATE END
      SimpleAdapter simpleAdapter = new SimpleAdapter(this, studentList,
              android.R.layout.simple_list_item_1,
              new String[] { "Students" }, new int[] { android.R.id.text1 });
      listView.setAdapter(simpleAdapter);
      Toast.makeText(getApplication(), "Logged in Successfully", Toast.LENGTH_SHORT).show();
  
  }
  
  private HashMap&lt;String, String&gt; createStudent(String name, String number) {
      HashMap&lt;String, String&gt; Students = new HashMap&lt;String, String&gt;();
      Students.put(name, number);
      return Students;
  }
  </code></pre>
  
  <p>}  </p>
  
  <p>MY Profile Activity</p>
  
  <pre><code>public class Profile extends Activity {
  
  TextView stud_name,stud_id;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.profile_layout);
  
      stud_name = (TextView)findViewById(R.id.student_name);
      stud_id = (TextView)findViewById(R.id.student_id);
      Bundle bundle = getIntent().getExtras();
      stud_name.setText("Student name: "+bundle.getString("student_name"));
      stud_id.setText("Student ID: "+bundle.getString("student_id"));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I think my problem is in my php how do i configure this
  if im using the bundle method? to get the string data from mysql and send it to Profile activity after i click one item from ListView?</p>
  
  <pre><code>&lt;?php
  $host="localhost";
  $username="thesis"; 
  $password="thesis123"; 
  $db_name="professor_db";
  $con=mysql_connect("$host", "$username", "$password")or die("cannot      connect"); 
  mysql_select_db("$db_name")or die("cannot select DB");
  $sql = "select * from student_info"; 
  $result = mysql_query($sql);
  $json = array();
  if(mysql_num_rows($result)){
  while($row=mysql_fetch_assoc($result)){
  $json['student_info'][]=$row;
  }
  }
  mysql_close($con);
  echo json_encode($json); 
  ?&gt;    
  </code></pre>