0

i have baseadapter and i try to adapter some values in listview.i loged strings witch i adaptered in baseadapter and i have diliver different result.in BaseAdapter Class also logend this texts and this both text are different this is a my Main Java source

public class MoviesRolls extends Fragment {

public final static String TAG = MoviesRolls.class.getSimpleName();

private ListView holllistview;
private HollAdapters adapter;
public static ArrayList<CinemaInfoModel> cinemaInfoArray;
public static CinemaInfoModel timeInfo;


public static MoviesRolls newInstance() {
return new MoviesRolls();}


public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {

View rootView = inflater
        .inflate(R.layout.moviesholls, container, false);

holllistview = (ListView) rootView.findViewById(R.id.holllistview);

holllistview = (ListView) rootView.findViewById(R.id.holllistview);



ServerItems mainItem = MainmoviesList.arrayOfList
        .get(MainmoviesList.mPosition);

ArrayList<CinemaModel> cinemas = mainItem.getCinema();
ArrayList<CinemaInfoModel> infos = new ArrayList<CinemaInfoModel>();
for (int i = 0; i < cinemas.size(); i++) {
    CinemaModel cinema = cinemas.get(i);
    cinemaInfoArray = cinema.getCinemTimeInfo();
    for (int j = 0; j < cinemaInfoArray.size(); j++) {
        timeInfo = cinemaInfoArray.get(j);

        Log.wtf("logcat start time",
                timeInfo.getTimeformat().get(j));
        Log.wtf("log cat end time",
                timeInfo.getEndTimeFormat().get(
                        j));

        SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
        Date _d;
        try {
            SimpleDateFormat new_df = new SimpleDateFormat("d MMM");
            _d = df.parse(timeInfo.getTimeformat().get(
                    j));
            Date _d1 = df.parse(timeInfo.getEndTimeFormat().get(
                   j));
            String datetimeis = getDateDiffString(_d1, _d);
            int differentdays = Integer.parseInt(datetimeis);
            Log.e("Different is ", String.valueOf(differentdays));
            for (int k = 0; k < differentdays; k++) {

                String datetimeformat = dateFormatter(timeInfo
                        .getTimeformat().get(j));

                Date datetime = new_df.parse(datetimeformat);

                Calendar cal = Calendar.getInstance();
                cal.setTime(datetime);
                cal.add(Calendar.DATE, k);

                datetime = cal.getTime();

                String ttime = new_df.format(datetime);
                timeInfo.setStartTimePeriod(ttime);
                System.out.println(ttime);
            infos.add(timeInfo);
            }
        } catch (ParseException e) {

            e.printStackTrace();
        }


    }

    adapter = new HollAdapters(getActivity(), infos);
    holllistview.setAdapter(adapter);

}
return rootView;
}

   public String getDateDiffString(Date dateOne, Date dateTwo) {
   long timeOne = dateOne.getTime();
   long timeTwo = dateTwo.getTime();
   long oneDay = 1000 * 60 * 60 * 24;
   long delta = (timeTwo - timeOne) / oneDay;

   if (delta > 0) {

    for (int i = 0; i < delta; i++) {

    }
    return String.valueOf(delta);
} else {
    delta *= -1;
    return String.valueOf(delta);
    }
  }


public static String dateFormatter(String inputDate) {

String inputFormat = "MM/dd/yyyy";
String outputFormat = "d MMM";

Date parsed = null;
String outputDate = "";
try {
    SimpleDateFormat df_input = new SimpleDateFormat(inputFormat,
            new Locale("en", "US"));
    SimpleDateFormat df_output = new SimpleDateFormat(outputFormat,
            new Locale("en", "US"));

    parsed = df_input.parse(inputDate);
    outputDate = df_output.format(parsed);

    // Log.wtf("outputDate", outputDate);
} catch (Exception e) {
    outputDate = inputDate;
}
return outputDate;
  }
 }

and this is a my base adapter code

public class HollAdapters extends BaseAdapter {
private Context mContext;

private final ArrayList<CinemaInfoModel> hollitems1;

public HollAdapters(Context context, ArrayList<CinemaInfoModel> hollitems) {
    mContext = context;

    this.hollitems1 = hollitems;

}

@Override
public int getCount() {

    return hollitems1.size();
}

@Override
public Object getItem(int position) {

    return null;
}

@Override
public long getItemId(int position) {

    return position;
}

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

    ViewHolderItem viewHolder;

    if (convertView == null) {

        LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
        convertView = inflater.inflate(R.layout.cinema_holl_adapter,
                parent, false);

        viewHolder = new ViewHolderItem();
        viewHolder.start_time = (TextView) convertView
                .findViewById(R.id.adapter_day);

        convertView.setTag(viewHolder);

    } 
    viewHolder = (ViewHolderItem) convertView.getTag();

    CinemaInfoModel objectItem = hollitems1.get(position);
    if (objectItem != null) {




            String starttimes = objectItem.getStartTimePeriod().get(
                    position);


            viewHolder.start_time.setText(starttimes);
            Log.e("adapter start time", starttimes);



    }

    return convertView;

}

static class ViewHolderItem {
    private TextView start_time;

 }
}

this is a my logcat message's screenshot (i 'm new user and i can't post image)

i have not idea what is a wrong in my code... if anyone knows solution please help me thanks

Don Chakkappan
  • 7,397
  • 5
  • 44
  • 59
baggio
  • 11
  • 8
  • 2
    What exactly do you want? – gegobyte Dec 11 '14 at 12:58
  • Could please be more specific? What results You want to have? what exactly is going wrong? – Opiatefuchs Dec 11 '14 at 12:59
  • @ Opiatefuchs please see my picture.in red line is baseadapter getStartTimePeriod message and in green line as MoviesRolls class 's setStartTimePeriod message and there both are different.i want to recive same as MoviesRolls class 's setStartTimePeriod message – baggio Dec 11 '14 at 13:02
  • Please do not duplicate your questions, this identical to [link](http://stackoverflow.com/questions/27421010/android-base-adapter-does-not-adapter-all-rows/27421265#27421265) – Kelevandos Dec 11 '14 at 13:04
  • @Kelevandos sorry i 'm new user and .... help me if you can sir – baggio Dec 11 '14 at 13:05

1 Answers1

0

Try this , Please change you code like this. If convertView is null means it will inflate layout, Else it will reuse the view. Let me know if you need any clarification

  if (convertView == null) {

    LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
    convertView = inflater.inflate(R.layout.cinema_holl_adapter,
            parent, false);

    viewHolder = new ViewHolderItem();
    viewHolder.start_time = (TextView) convertView
            .findViewById(R.id.adapter_day);

    convertView.setTag(viewHolder);

}else{
viewHolder = (ViewHolderItem) convertView.getTag();
}
/*** Do your stuff here***/
Murali Ganesan
  • 2,925
  • 4
  • 20
  • 31