title: JSon array response on gridview in Fragment
body: <p>i'm new on android developing and i have to learn much much more. I have an activity that uses fragments. Opening main activity, it shows 3 fragments and using json i have created an Array that contains an ID and a Name. I haven't understood yet, how to put my array data in a gridview and then how use it on a fragment. Can someone help me? Here my MainActivity</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements ActionBar.TabListener {
  
  SectionsPagerAdapter mSectionsPagerAdapter;
  ViewPager mViewPager;
  String myJSON;
  private ProgressDialog pDialog;
  
  
  
  private static final String TAG_RESULTS = "result";
  private static final String TAG_ID = "ID";
  private static final String TAG_NAME = "Nome";
  
  
  JSONArray serv_man = null;
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; tableList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      getData();
  
  
      // Set up the action bar.
      final ActionBar actionBar = getSupportActionBar();
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
      // Create the adapter that will return a fragment for each of the three
      // primary sections of the activity.
      mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  
      // Set up the ViewPager with the sections adapter.
      mViewPager = (ViewPager) findViewById(R.id.pager);
      mViewPager.setAdapter(mSectionsPagerAdapter);
  
       mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageSelected(int position) {
              actionBar.setSelectedNavigationItem(position);
          }
      });
  
      for (int i = 0; i &lt; mSectionsPagerAdapter.getCount(); i++) {           actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
      }
  }
  protected void showList(){
      try {
          JSONObject jsonObj = new JSONObject(myJSON);
          serv_man = jsonObj.getJSONArray(TAG_RESULTS);
  
          for(int i=0;i&lt;serv_man.length();i++){
              JSONObject c = serv_man.getJSONObject(i);
              String id = c.getString(TAG_ID);
              String name = c.getString(TAG_NAME);
  
              HashMap&lt;String,String&gt; persons = new HashMap&lt;String,String&gt;();
  
              persons.put(TAG_NAME,name);
              persons.put(TAG_ID, id);
              tableList.add(persons);
          }
  </code></pre>
  
  <p>// Here i should create view but i don't know how yet</p>
  
  <pre><code>    } catch (JSONException e) {
          e.printStackTrace();
      }
  
  }
  public void getData(){
      class GetDataJSON extends AsyncTask&lt;String, Void, String&gt; {
  
          @Override
          protected String doInBackground(String... params) {
              DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
              HttpPost httppost = new HttpPost("http://mysite/get_collab.php");
  
  
              httppost.setHeader("Content-type", "application/json");
              InputStream inputStream = null;
              String result = null;
              try {
                  HttpResponse response = httpclient.execute(httppost);
                  HttpEntity entity = response.getEntity();
  
                  inputStream = entity.getContent();
                  // json is UTF-8 by default
                  BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                  StringBuilder sb = new StringBuilder();
  
                  String line = null;
                  while ((line = reader.readLine()) != null)
                  {
                      sb.append(line + "\n");
                  }
                  result = sb.toString();
                  Log.d("Log_Tag","xxx" + result);
  </code></pre>
  
  <p>// Here i can see that result is ok</p>
  
  <pre><code>            } catch (Exception e) {
                  // Oops
                  Log.e("log_tag", "Error converting result " + e.toString());
              }
              finally {
                  try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
              }
              return result;
          }
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(MainActivity.this);
              pDialog.setMessage("Obtaining list...");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(true);
              pDialog.show();
          }
  
  
          @Override
          protected void onPostExecute(String result){
              pDialog.dismiss();
              myJSON=result;
              showList();
          }
      }
      GetDataJSON g = new GetDataJSON();
      g.execute();
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, 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();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
      // When the given tab is selected, switch to the corresponding page in
      // the ViewPager.
      mViewPager.setCurrentItem(tab.getPosition());
  }
  
  @Override
  public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  }
  
  @Override
  public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
  }
  
  public class SectionsPagerAdapter extends FragmentPagerAdapter {
      public SectionsPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          Fragment fragment = null;
          switch (position) {
              case 0:
                  fragment = new PpFragment();
                  break;
              case 1:
                  fragment = new ScndFragment();
  
                  break;
              case 2:
                  fragment = new thrdFragment();
  
          }
          return fragment;
      }
  
      @Override
      public int getCount() {
          // Show 3 total pages.
          return 3;
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          Locale l = Locale.getDefault();
          switch (position) {
              case 0:
                  return getString(R.string.title_section1).toUpperCase(l);
              case 1:
                  return getString(R.string.title_section2).toUpperCase(l);
              case 2:
                  return getString(R.string.title_section3).toUpperCase(l);
          }
          return null;
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>// I should want to create a view with a gridview that shows Name and eventually a standard picture like a card view but probably it's really too much for me. I can only hope in your help.
  Thanks</p>