单击项目时出现null listview?

时间:2016-05-29 15:52:10

标签: android listview

当我点击gridview上的项目时,它应该显示我即将推出的游戏列表,但它会给我null listview ...为什么?

这是代码:

private View.OnClickListener getGamesByDate(final String[] date, final ListView luListView) {
            return new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // send post request to get game by date and Plyid
                    Log.e("DATE", date[0]+"-"+date[1]+"-"+date[2]);
                    String dt = date[0] + "-" + date[1] + "-" + date[2];
                    //  2016-02-18 the date in the hashmap of games
                    GameEvent gm = ViewUpcomingGmsAsyncTask.hashUpcoming.get(dt);
                   // ViewUpcomingGmsAsyncTask playerEvents = new ViewUpcomingGmsAsyncTask(new ProgressDialog(mContext), mContext,gridview );
                    Log.e("tabs",""+luListView);

                    ProgressDialog progress= new ProgressDialog(mContext);
                  /*  GamesAdapter upcomingAdapter = new GamesAdapter(arrayLists,mContex,lvupcoming,3);
                    lvupcoming.setAdapter(upcomingAdapter);*/

                    new ViewUpcomingGmsAsyncTask(progress,mContext,luListView).execute();
                   // Log.e("tabs",""+luListView);


                    if (gm!=null){
                        Bundle mBundle = new Bundle();
                        mBundle.putSerializable("gm",gm);
                        GameDetailsFragment GameDetails=GameDetailsFragment.newInstance();
                        GameDetails.setArguments(mBundle);
                        mContext.getSupportFragmentManager().beginTransaction().replace(R.id.container,
                                GameDetails,"gmDetails").addToBackStack("gmDetails").commit();

                    }
    }
};}

所有代码:

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;

import fastplay.netcharizma.com.fastplay.Fragments.GameDetailsFragment;
import fastplay.netcharizma.com.fastplay.R;
import fastplay.netcharizma.com.fastplay.Utils.GameActions;
import fastplay.netcharizma.com.fastplay.asyncTask.CalLstAsynck;
import fastplay.netcharizma.com.fastplay.asyncTask.ViewUpcomingGmsAsyncTask;
import fastplay.netcharizma.com.fastplay.asyncTask.loginAsync;
import fastplay.netcharizma.com.fastplay.bean.GameEvent;

/**
* Created by root on 7/2/2015.
*/
public class CalendarAdapter extends BaseAdapter {
private FragmentActivity mContext;
private java.util.Calendar month;
public GregorianCalendar pmonth; // calendar instance for previous month
/**
 * calendar instance for previous month for getting complete view
 */
public GregorianCalendar pmonthmaxset;
private GregorianCalendar selectedDate;
private int firstDay;
private int maxWeeknumber;
private int maxP;
private int calMaxP;
private int lastWeekDay;
private int leftDays;
private int mnthlength;
private String itemvalue, curentDateString;
private DateFormat df;
private GameActions gmActions;
private  ArrayList<GameEvent> ev;

private ArrayList<String> items;
public static List<String> dayString;
private View previousView;
ListView lvupcoming;


public CalendarAdapter(FragmentActivity c, GregorianCalendar monthCalendar)     {

    CalendarAdapter.dayString = new ArrayList<>();
    Locale.setDefault(Locale.US);
    month = monthCalendar;
    selectedDate = (GregorianCalendar) monthCalendar.clone();
    mContext = c;
    month.set(GregorianCalendar.DAY_OF_MONTH, 1);
    this.items = new ArrayList<>();
    df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    curentDateString = df.format(selectedDate.getTime());
    refreshDays();
}

public void setItems(ArrayList<String> items) {
    for (int i = 0; i != items.size(); i++) {
        if (items.get(i).length() == 1) {
            items.set(i, "0" + items.get(i));
        }
    }
    this.items = items;
}

public int getCount() {
    if(dayString != null && dayString.size() >0) return dayString.size(); else return 0;
}

public Object getItem(int position) {
    return dayString.get(position);
}

public long getItemId(int position) {
    return 0;
}

// create a new view for each item referenced by the Adapter
public View getView(int position, final View convertView, ViewGroup parent) {
    View v = convertView;
    TextView dayView;




    if (convertView == null) { // if it's not recycled, initialize some
        // attributes
        LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.calendar_item, null);
        lvupcoming= (ListView) v.findViewById(R.id.lvupcoming);


    }
   // convertView.setTag();
    dayView = (TextView) v.findViewById(R.id.date);
    ImageView icon= (ImageView) v.findViewById(R.id.date_icon);
    // separates day string into parts.
    String[] separatedTime = dayString.get(position).split("-");
    // taking last part of date. ie; 2 from 2012-12-02
    String gridvalue = separatedTime[2].replaceFirst("^0*", "");
    // checking whether the day is in current month or not.
    if ((Integer.parseInt(gridvalue) > 1) && (position < firstDay)) {
        // setting off days to white color.
        dayView.setTextColor(Color.GRAY);
        dayView.setClickable(false);
        dayView.setFocusable(false);
    } else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) {
        dayView.setTextColor(Color.GRAY);
        dayView.setClickable(false);
        dayView.setFocusable(false);
    } else {
        // setting curent month's days in blue color.
        dayView.setTextColor(Color.WHITE);
    }

    if (dayString.get(position).equals(curentDateString)) {
        setSelected(v);
        previousView = v;
    } else {
        v.setBackgroundResource(R.drawable.list_item_background);
    }
    dayView.setText(gridvalue);

    // create date string for comparison
    String date = dayString.get(position);

    if (date.length() == 1) {
        date = "0" + date;
    }

    String monthStr = "" + (month.get(GregorianCalendar.MONTH) + 1);
    if (monthStr.length() == 1) {
        monthStr = "0" + monthStr;
    }
    // show icon if date is not empty and it exists in the items array
    ImageView iw = (ImageView) v.findViewById(R.id.date_icon);
    if (date.length() > 0 && items != null && items.contains(date)) {
        iw.setVisibility(View.VISIBLE);

    } else {
        iw.setVisibility(View.INVISIBLE);
    }
    v.setOnClickListener(getGamesByDate(separatedTime));

    v.setOnClickListener(getGamesByDate(separatedTime,lvupcoming));

    return v;
}

private View.OnClickListener getGamesByDate(final String[] date) {
    return new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // send post request to get game by date and Plyid
            Log.e("DATE", date[0]+"-"+date[1]+"-"+date[2]);
            String dt = date[0] + "-" + date[1] + "-" + date[2];
            //  2016-02-18 the date in the hashmap of games
            GameEvent gm = ViewUpcomingGmsAsyncTask.hashUpcoming.get(dt);




        if (gm!=null){
            Bundle mBundle = new Bundle();
            mBundle.putSerializable("gm",gm);
            GameDetailsFragment GameDetails=GameDetailsFragment.newInstance();
            GameDetails.setArguments(mBundle);
            mContext.getSupportFragmentManager().beginTransaction().replace(R.id.container,
                    GameDetails,"gmDetails").addToBackStack("gmDetails").commit();
        }
        }
    };}
        private View.OnClickListener getGamesByDate(final String[] date, final ListView luListView) {
            return new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // send post request to get game by date and Plyid
                    Log.e("DATE", date[0]+"-"+date[1]+"-"+date[2]);
                    String dt = date[0] + "-" + date[1] + "-" + date[2];
                    //  2016-02-18 the date in the hashmap of games
                    GameEvent gm = ViewUpcomingGmsAsyncTask.hashUpcoming.get(dt);
                   // ViewUpcomingGmsAsyncTask playerEvents = new ViewUpcomingGmsAsyncTask(new ProgressDialog(mContext), mContext,gridview );
                    Log.e("tabs",""+luListView);

                    ProgressDialog progress= new ProgressDialog(mContext);
                  /*  GamesAdapter upcomingAdapter = new GamesAdapter(arrayLists,mContex,lvupcoming,3);
                    lvupcoming.setAdapter(upcomingAdapter);*/

                    new ViewUpcomingGmsAsyncTask(progress,mContext,luListView).execute();
                   // Log.e("tabs",""+luListView);


                    if (gm!=null){
                        Bundle mBundle = new Bundle();
                        mBundle.putSerializable("gm",gm);
                        GameDetailsFragment GameDetails=GameDetailsFragment.newInstance();
                        GameDetails.setArguments(mBundle);
                        mContext.getSupportFragmentManager().beginTransaction().replace(R.id.container,
                                GameDetails,"gmDetails").addToBackStack("gmDetails").commit();

                    }
    }
};}

public View setSelected(View view) {
    if (previousView != null) {
        previousView.setBackgroundResource(R.drawable.list_item_background);
    }
    previousView = view;
    view.setBackgroundResource(R.drawable.calendar_cel_select);

    return view;

}

public void refreshDays() {
    // clear items
    items.clear();
    dayString.clear();
    Locale.setDefault(Locale.US);
    pmonth = (GregorianCalendar) month.clone();
    // month start day. ie; sun, mon, etc
    firstDay = month.get(GregorianCalendar.DAY_OF_WEEK);
    // finding number of weeks in current month.
    maxWeeknumber = month.getActualMaximum(GregorianCalendar.WEEK_OF_MONTH);
    // allocating maximum row number for the gridview.
    mnthlength = maxWeeknumber * 7;
    maxP = getMaxP(); // previous month maximum day 31,30....
    calMaxP = maxP - (firstDay - 1);// calendar offday starting 24,25 ...
    /**
     * Calendar instance for getting a complete gridview including the three
     * month's (previous,current,next) dates.
     */
    pmonthmaxset = (GregorianCalendar) pmonth.clone();
    /**
     * setting the start date as previous month's required date.
     */
    pmonthmaxset.set(GregorianCalendar.DAY_OF_MONTH, calMaxP + 1);

    /**
     * filling calendar gridview.
     */
    for (int n = 0; n < mnthlength; n++) {
        itemvalue = df.format(pmonthmaxset.getTime());
        pmonthmaxset.add(GregorianCalendar.DATE, 1);
        dayString.add(itemvalue);
    }
}

private int getMaxP() {
    int maxP;
    if (month.get(GregorianCalendar.MONTH) == month.getActualMinimum(GregorianCalendar.MONTH)) {
        pmonth.set((month.get(GregorianCalendar.YEAR) - 1),
                month.getActualMaximum(GregorianCalendar.MONTH), 1);
    } else {
        pmonth.set(GregorianCalendar.MONTH,
                month.get(GregorianCalendar.MONTH) - 1);
    }
    maxP = pmonth.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
    return maxP;
}


private void plotDataOnGridPerMonth(){
    // get string months string arrays and match it with hashmap of dates=>events
    // to acquire game object then redirect to game details fragment


}

logcat https://drive.google.com/file/d/0B4qSbUozI6X9WkF2WkpLcHdaOEU/view

我想用gameevent的日期显示listview ....  任何人都可以找到这个问题的解决方案吗?

0 个答案:

没有答案