滚动后为什么文本会在listview中显示?

时间:2016-12-21 12:54:35

标签: android json listview textview

下面是我的日历日视图适配器。现在我希望数据来自服务器,但是当我滚动listview时它显示。我希望在活动启动时滚动显示数据。我怎样才能做到这一点?

public class SearchListAdapter extends BaseAdapter {
        private Activity activity;
        private LayoutInflater inflater;
        private List<Details> movieItems;

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

        @Override
        public int getCount() {
            return HOURS_PER_DAY;
        }

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

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

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

            LayoutInflater inflater = getLayoutInflater();
            convertView = (View) inflater.inflate(R.layout.list_item_appointment, listView, false);

            TextView hourTV = (TextView) convertView.findViewById(R.id.hourTV);
            TextView amTV = (TextView) convertView.findViewById(R.id.amTV);

            hourTV.setTextColor(Color.parseColor("#2c3c53"));
            amTV.setTextColor(Color.parseColor("#2c3c53"));

            final LinearLayout eventsLL = (LinearLayout) convertView.findViewById(R.id.eventsLL);
            int val = position % 24;
            Typeface face = Typeface.createFromAsset(getAssets(), "fonts/centurygothic.ttf");
            hourTV.setTypeface(face);
            amTV.setTypeface(face);
            if (val < 10) {
                hourTV.setText(String.valueOf((val + 6) + ":" + "00"));
            } else {
                hourTV.setText(String.valueOf((val + 6) + ":" + "00"));
            }


            if (val == 7)
                hourTV.setText("1" + ":" + "00");

            if (val == 8)
                hourTV.setText("2" + ":" + "00");

            if (val == 9)
                hourTV.setText("3" + ":" + "00");

            if (val == 10)
                hourTV.setText("4" + ":" + "00");

            if (val == 11)
                hourTV.setText("5" + ":" + "00");

            if (val == 12)
                hourTV.setText("6" + ":" + "00");

            if (val == 13)
                hourTV.setText("7" + ":" + "00");

            if (val == 14)
                hourTV.setText("8" + ":" + "00");

            if (val == 15)
                hourTV.setText("9" + ":" + "00");

            if (val == 16)
                hourTV.setText("10" + ":" + "00");

            if (val == 17)
                hourTV.setText("11" + ":" + "00");

            if ((position + 6 >= 0) && (position + 6 < 12))
                amTV.setText("am");
            else
                amTV.setText("pm");

            if (details_list.size() > 0) {

                for (int i = 0; i < details_list.size(); i++) {
                    String[] innerData2 = details_list.get(i).getTime().split(":");
                    str = innerData2[0];

                    try {

                        int s = ((position) % 24) + 6;
                        if ((s) == Integer.parseInt(str)) {
                            TextView rowTextView = new TextView(AppointmentDayView.this);

                            indexmap_aptid.put(position, details_list.get(i).getAppointmentId());
                            indexmap_clocid.put(position, details_list.get(i).getClientLocationId());
                            indexmap_appDate.put(position, details_list.get(i).getStartAppointmentDate());

                            rowTextView.setPadding(10, 20, 10, 20);
                            rowTextView.setBackgroundResource(R.drawable.borderdayview);
                            rowTextView.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
                            rowTextView.setTextSize(14);
                            rowTextView.setTypeface(face);
                            rowTextView.setTypeface(Typeface.DEFAULT_BOLD);


                            String start_time = "", end_time = "";

                            try {
                                String dt = details_list.get(i).getTime();
                                String end = details_list.get(i).getEndtime();
                                DateFormat df = new SimpleDateFormat("hh:mm:ss");
                                DateFormat dft = new SimpleDateFormat("hh:mm a");

                                Date dts = df.parse(dt);
                                Date end_t = df.parse(end);

                                start_time = dft.format(dts);
                                end_time = dft.format(end_t);
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }


                            rowTextView.setText("Name : " + details_list.get(i).getName() + "\n" +
                                    "Time " + start_time + " To " + end_time + "\n"
                                    + "Reason : " + details_list.get(i).getReason() + " ");

                            eventsLL.addView(rowTextView);

                        }

                        for (int k = 0; k < details_list.size(); k++) {

                            String in[] = details_list.get(k).getTime().split(":");
                            String out[] = details_list.get(k).getEndtime().split(":");

                            int stime = Integer.parseInt(in[0]);
                            int end = Integer.parseInt(out[0]);

                            int start = stime + 1;
                            while (start <= end) {

                                int q = ((position) % 24) + 6;
                                if ((q) == start) {

                                    TextView rowTextView = new TextView(AppointmentDayView.this);
                                    rowTextView.setPadding(10, 20, 10, 20);
                                    rowTextView.setBackgroundResource(R.drawable.borderdayview);
                                    rowTextView.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
                                    rowTextView.setTextSize(14);
                                    rowTextView.setTypeface(face);
                                    rowTextView.setTypeface(Typeface.DEFAULT_BOLD);
                                    eventsLL.addView(rowTextView);

                                }
                                start++;
                            }
                        }

                    } catch (ArrayIndexOutOfBoundsException e) {

                    }

                }
            }

            return convertView;
        }

    }

0 个答案:

没有答案