2017-09-29 12 views
0

私の画像グリッドビューが表示されていません。データベースからフェッチされたURLを使用してPicasaを使用してグリッド上の画像を表示しています。それはそれを示してフラグメントに何か他のものは、問題はちょうど私があなたが嘆願 を助けることができるかのいずれかのエラーを取得しておりませんグリッドであり、これは画像Gridviewが分割で表示されていない

public class event extends Fragment { 
int userid ; 
String START ; 
private String GET_IMAGES_URL = 
"http://192.168.1.107/android/v1/getimages.php"; 
public static final String TAG_IMAGE_URL = "URL"; 
private GridView gridView; 
private ArrayList<String> images; 
private static final String ARG_PARAM1 = "param1"; 
private static final String ARG_PARAM2 = "param2"; 
private String mParam1; 
private String mParam2; 
private OnFragmentInteractionListener mListener; 
public event() { 
     } 
public static event newInstance(String param1, String param2) { 
    event fragment = new event(); 
    Bundle args = new Bundle(); 
    args.putString(ARG_PARAM1, param1); 
    args.putString(ARG_PARAM2, param2); 
    fragment.setArguments(args); 
    return fragment; 
} 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if (getArguments() != null) { 
     mParam1 = getArguments().getString(ARG_PARAM1); 
     mParam2 = getArguments().getString(ARG_PARAM2); 
    } 
    userid = SharedPrefManager.getInstance(getActivity()).getUserid(); 
    images = new ArrayList<>(); 
    START = ""; 
} 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_event, container, false); 
    gridView = (GridView) view.findViewById(R.id.gridview); 
    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View v, 
           int position, long id) { 
      Toast.makeText(getActivity(), "" + position, 
        Toast.LENGTH_SHORT).show(); 
     } 
    }); 
    getData(); 
    return view; 
    } 
    public void onButtonPressed(Uri uri) { 
    if (mListener != null) { 
     mListener.onFragmentInteraction(uri); 
    } 
    } 
    @Override 
    public void onAttach(Context context) { 
    super.onAttach(context); 
    if (context instanceof OnFragmentInteractionListener) { 
     mListener = (OnFragmentInteractionListener) context; 
    } else { 
    } 
    } 
    @Override 
    public void onDetach() { 
    super.onDetach(); 
    mListener = null; 
    } 
    public interface OnFragmentInteractionListener { 
    // TODO: Update argument type and name 
    void onFragmentInteraction(Uri uri); 
    } 
    private void getData() { 
    final ProgressDialog loading = ProgressDialog.show(getActivity(), 
    "Please wait...", "Fetching data...", false, false); 
    StringRequest stringRequest = new StringRequest(
      Request.Method.POST, GET_IMAGES_URL, 
      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 
        try { 
         JSONArray array = new JSONArray(response); 
          loading.dismiss(); 
          showGrid(array); 
        } catch (JSONException e) { 

         loading.dismiss(); 
         e.printStackTrace(); 
        } 
       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        loading.dismiss(); 

       } 
      } 
    ){ 
     @Override 
     protected Map<String, String> getParams() throws AuthFailureError { 
      Map<String, String> params = new HashMap<>(); 
      params.put("userid", String.valueOf(userid)); 

      return params; 
     } 

    };; 


    RequestQueue requestQueue = Volley.newRequestQueue(getActivity()); 


    requestQueue.add(stringRequest); 
    } 
    private void showGrid(JSONArray array){ 

    for(int i = 0; i<array.length(); i++){ 

     JSONObject obj = null; 
     try { 

      images.add(START + array.getString(i)+START); 




     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
    } 

    gridView.setAdapter(new 
    GridViewAdapter(getActivity().getApplicationContext(),images)); 
    } 

    } 

私のアダプタクラスは、この

である私のfragment.javaコードです
public class GridViewAdapter extends BaseAdapter { 
    private final Context context; 
    ArrayList<String> urls; 
    // private String[] url ; 
    public GridViewAdapter(Context context, ArrayList<String> images) { 
    this.context = context; 
    urls =images; 
    } 

    @Override public View getView(int position, View convertView, ViewGroup 
    parent) { 
    ImageView view = (ImageView) convertView; 
    if (view == null) { 
     view = new ImageView(context); 

     view.setLayoutParams(new GridView.LayoutParams(85, 85)); 
     view.setScaleType(ImageView.ScaleType.CENTER_CROP); 
     view.setPadding(8, 8, 8, 8); 
    } 
    else { 
     view = (ImageView) convertView; 
    } 

    // Get the image URL for the current position. 
    String url = getItem(position); 
    // 

    // Trigger the download of the URL asynchronously into the image view. 
    Picasso.with(context) // 
      .load(url) // 
      .fit() // 
      .tag(context) // 
      .into(view); 


    return view; 
    } 

    @Override public int getCount() { 
    return urls.size(); 
    } 

    @Override public String getItem(int position) { 
    return urls.get(position); 
    } 

    @Override public long getItemId(int position) { 
    return position; 
    } 

    } 

答えて

0

ピカソはインターネットペルミあなたのマニフェストにあるシオン。

関連する問題