2016-04-03 31 views
0

リストビューを表示することができないという点で、jsonを使用してデータをロードするフラグメントビューのリストビューを使用しています。私はコードで間違っています。サーバーの部分は正常に動作します。リストビューの内容を見ることができません

フラグメント:

public class SchedulessFragment extends Fragment{ 
private static final String TAG = MatAct.class.getSimpleName(); 
private static final String url = "http://nammakovai2015-001-site1.1tempurl.com/iplspin/schedules.php"; 
ProgressDialog pDialog; 
List<Sched> movieList = new ArrayList<Sched>(); 
ListView listview; 
CustomListAdapter adapter; 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.schedule_frag, container, false); 
    adapter = new CustomListAdapter(getActivity(), movieList); 
    listview = (ListView) v.findViewById(R.id.listView1); 

    listview.setAdapter(adapter); 
    // TextView tv = (TextView) v.findViewById(R.id.tvfrag); 
    // tv.setText(getArguments().getString("msg")); 
    // tv.setText("Hello"); 
    pDialog = new ProgressDialog(getActivity()); 
    // Showing progress dialog before making http request 
    pDialog.setMessage("Loading..."); 
    pDialog.show(); 

    // changing action bar color 


    // Creating volley request obj 
    JsonArrayRequest movieReq = new JsonArrayRequest(url, 
      new Response.Listener<JSONArray>() { 
       @Override 
       public void onResponse(JSONArray response) { 
        Log.d(TAG, response.toString()); 
        hidePDialog(); 

        // Parsing json 
        for (int i = 0; i < response.length(); i++) { 
         try { 

          JSONObject obj = response.getJSONObject(i); 
          Sched m = new Sched(); 
          m.setTeama(obj.getString("teama")); 

          m.setTeamb(obj.getString("teamb")); 
          m.setTdate(obj.getString("tdate")); 
          m.setTtime(obj.getString("ttime")); 
          m.setThumbnailUrl(obj.getString("thumbnailUrl")); 
          m.setTeambthumbnailUrl(obj.getString("teambthumbnailUrl")); 
          m.setVenue(obj.getString("venue")); 


          // adding movie to movies array 
          movieList.add(m); 

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

        } 

        // notifying list adapter about data changes 
        // so that it renders the list view with updated data 
        adapter.notifyDataSetChanged(); 
       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      VolleyLog.d(TAG, "Error: " + error.getMessage()); 
      hidePDialog(); 

     } 
    }); 

    // Adding request to request queue 
    AppController.getInstance().addToRequestQueue(movieReq); 

    return v; 
} 
@Override 
public void onDestroy() { 
    super.onDestroy(); 
    hidePDialog(); 
} 

private void hidePDialog() { 
    if (pDialog != null) { 
     pDialog.dismiss(); 
     pDialog = null; 
    } 
} 
public static SchedulessFragment newInstance(String text) { 

    SchedulessFragment f = new SchedulessFragment(); 
    Bundle b = new Bundle(); 
    b.putString("msg", text); 

    f.setArguments(b); 

    return f; 
}} 

ListAdapter:

public class CustomListAdapter extends BaseAdapter{ 
private Activity activity; 
private LayoutInflater inflater; 
List<Sched> movieItems; 
ImageLoader imageLoader = AppController.getInstance().getImageLoader(); 

public CustomListAdapter(Activity activity, List<Sched> movieItems) { 
    this.activity = activity; 
    this.movieItems = movieItems; 
} 

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

@Override 
public Object getItem(int location) { 
    return movieItems.get(location); 
} 

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

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    if (inflater == null) 
     inflater = (LayoutInflater) activity 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    if (convertView == null) 
     convertView = inflater.inflate(R.layout.listitem_ros, null); 

    if (imageLoader == null) 
     imageLoader = AppController.getInstance().getImageLoader(); 
    NetworkImageView thumbNail = (NetworkImageView) convertView 
      .findViewById(R.id.pict); 
    NetworkImageView teambthumbnail=(NetworkImageView) convertView.findViewById(R.id.pict1); 
    TextView teama = (TextView) convertView.findViewById(R.id.scheduleteama_name); 
    TextView teamb = (TextView) convertView.findViewById(R.id.schduleteamb_name); 
    TextView tdate = (TextView) convertView.findViewById(R.id.datess); 
    TextView ttime = (TextView) convertView.findViewById(R.id.timess); 
    TextView venue=(TextView)convertView.findViewById(R.id.schedulevenue); 
    // getting movie data for the row 
    Sched m = movieItems.get(position); 

    // thumbnail image 
    thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader); 
    teambthumbnail.setImageUrl(m.getTeambthumbnailUrl(),imageLoader); 
    // title 
    teama.setText(m.getTeama()); 
    teamb.setText(m.getTeamb()); 
    tdate.setText(m.getTdate()); 
    ttime.setText(m.getTtime()); 
    venue.setText(m.getVenue()); 


    return convertView; 
}} 

SCHED:

XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 
<ListView 
    android:id="@+id/listView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:dividerHeight="1dp" 
    > 
</ListView> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:id="@+id/tvfrag" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="219dp" /> 
+0

あなたが最初のティムに来るとき、あなたのarraylistはnullであり、アダプタを設定するか、あなたのデータがarraylistに埋め込まれたときにアダプタを設定するか、 –

答えて

0

あなたの問題は、movieListが実装される前にアダプタを作成していることです。あなたがリストに動画を追加していた中で、forループの後

adapter = new CustomListAdapter(getActivity(), movieList); 
    listview.setAdapter(adapter); 

:この2行を移動し

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

         JSONObject obj = response.getJSONObject(i); 
         Sched m = new Sched(); 
         m.setTeama(obj.getString("teama")); 

         m.setTeamb(obj.getString("teamb")); 
         m.setTdate(obj.getString("tdate")); 
         m.setTtime(obj.getString("ttime")); 
         m.setThumbnailUrl(obj.getString("thumbnailUrl")); 
         m.setTeambthumbnailUrl(obj.getString("teambthumbnailUrl")); 
         m.setVenue(obj.getString("venue")); 


         // adding movie to movies array 
         movieList.add(m); 

        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
//PUT THOSE TWO LINES HERE 

あなたRequestが良好であり、それが空でないJSONArray、これを返すと仮定すると、うまくいくはずです。

+0

いいえうまくいかず、私が上に与えたファイルは、コンストラクタが使用されることはありません。何か問題があります。パブリックSched(文字列、文字列、文字列tdate、文字列ttime、文字列thumbnailUrl、文字列の文字列、文字列の場所) { this.teama = teama; this.teamb = teamb; this.tdate = tdate; this.ttime = ttime; this.thumbnailUrl = thumbnailUrl; this.teambthumbnailUrl = teambthumbnailurl; this.venue =会場; } – nick

+0

コンストラクタは2つありますが、** empty **コンストラクタのみを使用しているため、パラメータを持つコンストラクタは使用されません。 – Vucko

+0

リストビューを表示しない場合でも、白い画面しか表示されません。 – nick

関連する問題