Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在水平列表视图中滚动到特定项目?_Java_Android_Scroll_Horizontallist - Fatal编程技术网

Java 如何在水平列表视图中滚动到特定项目?

Java 如何在水平列表视图中滚动到特定项目?,java,android,scroll,horizontallist,Java,Android,Scroll,Horizontallist,在下面的代码中,我在水平列表视图中实现了calander。 现在我想滚动到特定的日期,就像我要经过一样 22日期,所以它应该自动滚动到第21项。我有 尝试了horizontalListView.scrollTO(intx),但它不起作用。请 请帮助我,如果您需要更多关于以下代码的解释,请 我知道。我已经在这个URL上上传了整个班级 公共类MyAppointment扩展了BaseActivity实现OnClickListener, 数据侦听器{ 私人线路布置我的任命; 公共线路布局llCalTop

在下面的代码中,我在水平列表视图中实现了calander。 现在我想滚动到特定的日期,就像我要经过一样 22日期,所以它应该自动滚动到第21项。我有 尝试了horizontalListView.scrollTO(intx),但它不起作用。请 请帮助我,如果您需要更多关于以下代码的解释,请 我知道。我已经在这个URL上上传了整个班级

公共类MyAppointment扩展了BaseActivity实现OnClickListener,
数据侦听器{
私人线路布置我的任命;
公共线路布局llCalTop;
私有列表视图任命扩展列表;
私人阿里尔主义者;
private ArrayList childs1、childs2、childs3;
私人任命列表适配器;
私有哈希映射;
专用向量机;
布尔标志=真;
私人视图monthview;
私人约会背景;
私有文本视图tvSelMonthYear;
公众观点;
私有视图;
私人线路布局有限责任公司;
静态日历;
私人日历CalNext;
私人日历CalPrev;
私人int月,年;
TextView tvPrevMonthClick,tvNextMonthClick;
私人日历;
静态字符串calSelectedDate;
私有图像视图ivCalRightArrow,IVCalleTarrow;
公共静态整数宽度;
//------------------------------------滑动日历
//变数------------------------------------//
私人HorizontallistView项目;
专用日历适配器日历适配器;
私密文本查看电视月;
私有图像视图左、右;
私人日历cal;
私人公用;
私人请求做请求做;
私有字符串appointmentdate=“”,appointmenttime=“”;
//-----所选日期初始化为-1,因为0是最小值
//在加兰德-----//
int selectedDay=-1,selectedMonth=-1,selectedYear=-1;
// -------------------------------------------------*/*---------------------------------------//
@SuppressLint(“新API”)
@凌驾
公共无效初始化(){
我的约会=(线性布局)充气器。充气(
R.layout.my_\u layout,null);
llCalTop=(LinearLayout)myAppointment.findViewById(R.id.llCalTop);
llBody.addView(我的约会,新的布局参数(
LayoutParams.MATCH_父级,LayoutParams.MATCH_父级);
appointmentsExpandableList=(ListView)findViewById(R.id.appointmentsExpandableList);
ivHeaderRight=(ImageView)findViewById(R.id.ivHeaderRight);
//initLists();
vecRequestDOs=新的MyAppointsDA()
.GetAllitiveSBYID(“31-01-2015”);
adapter=new AppointmentListAdapter(MyAppointment.this,vecRequestDOs);
header.setText(“我的约会”);
appointmentsExpandableList.setAdapter(适配器);
ivHeaderRight.setVisibility(视图.可见);
ivHeaderRight.setImageResource(R.drawable.cal);
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
国际单项体育联合会(旗){
ivHeaderRight.setImageResource(R.drawable.list);
flag=false;
oldView=findviewbyd(R.id.llCalTop);
//
show();
}否则{
ivHeaderRight.setImageResource(R.drawable.cal);
flag=true;
oldView=(线性布局)充气器。充气(
R.layout.my_\u layout,null);
llCalTop.setLayoutParams(新的LinearLayout.LayoutParams(
LayoutParams.MATCH_父级,
LayoutParams.MATCH_PARENT));
llCalTop.removeallview();
selectedDay=CustomCalendar.todayDate;
选择的月份=CustomCalendar.month;
selectedYear=CustomCalendar.year;
llCalTop.addView(旧视图,新布局参数(
LayoutParams.MATCH_父级,
LayoutParams.MATCH_PARENT));
sliderCalendar();
}
}
});
sliderCalendar();
}
@SuppressLint(“新API”)
公开展览({
monthview=充气机。充气(R.layout.monthview\u cal,空);
monthview.setLayoutParams(新的LinearLayout.LayoutParams(
LayoutParams.MATCH_父级,LayoutParams.MATCH_父级);
llCalTop.removeallview();
llCalTop.addView(monthview,新的LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
context=MyAppointment.this;
Display Display=getWindowManager().getDefaultDisplay();
点大小=新点();
display.getSize(size);
int width=size.x;
CustomCalendar.Calendar\u单元格\u宽度=宽度/7;
tvSelMonthYear=(TextView)findViewById(R.id.tvSelMonthYear);
llcalBody=(LinearLayout)findViewById(R.id.llcalBody);
tvPrevMonthClick=(TextView)findViewById(R.id.prevMonth);
tvNextMonthClick=(文本视图)findViewById(R.id.nextMonth);
IVCalleTarrow=(ImageView)findViewById(R.id.IVCalleTarrow);
ivCalRightArrow=(ImageView)findViewById(R.id.ivCalRightArrow);
tvSelMonthYear.setTextSize(16);
calendar=calendar.getInstance();
如果(selectedDay!=-1&&selectedMonth!=-1&&selectedYear!=-1){
日历设置(选择年、选择月、选择日);
}
month=calendar.get(calendar.month);
year=calendar.get(calendar.year);
CalPrev=Calendar.getInstance();
CalPrev.add(日历月份,-1);
CalNext=Calendar.getInstance();
CalNext.add(Calendar.MONTH,1);
tvSelMonthYear.setText(CalendarUtility.getMonth(month)+“
+calendar.get(calendar.YEAR));
显示日历(月、年);
IVCalledError.setOnClickListener(此);
ivCalRightArrow.setOnClickListener(此);
}
@凌驾
公共void onClick(视图v){
if(v.getId()==R.id.ivcalledError){
calendar.add(calendar.MONTH,-1);
tvSelMonthYear.setText(CalendarUtility.getMonth(calendar
.get(日历.月份))+“”+c
public class MyAppointment extends BaseActivity implements OnClickListener,
    DataListener {
private LinearLayout myAppointment;
public LinearLayout llCalTop;
private ListView appointmentsExpandableList;
private ArrayList<String> alist;
private ArrayList<AppointmentDO> childs1, childs2, childs3;
private AppointmentListAdapter adapter;
private HashMap<String, ArrayList<AppointmentDO>> map;
private Vector<RequestDO> vecRequestDOs;
Boolean flag = true;
private View monthview;
private MyAppointment context;
private TextView tvSelMonthYear;
public View selView;
private View oldView;
private LinearLayout llcalBody;
static Calendar calendar;
private Calendar CalNext;
private Calendar CalPrev;
private int month, year;
TextView tvPrevMonthClick, tvNextMonthClick;
private CustomCalendar customCalender;
static String calSelectedDate;
private ImageView ivCalRightArrow, ivCalLeftArrow;
public static int width;
// ----------------------------------Slider calendar
// variables------------------------------------//
private HorizontialListView lvItems;
private CalendarAdapter calendarAdapter;
private TextView tvMonth;
private ImageView ivleft, ivright;
private Calendar cal;
private CommonBL commonBL;
private RequestDO requestDO;
private String appointmentdate = "", appointmenttime = "";

// -------- Selected date intializing with -1 because 0 is the minimum value
// in calander.-----//
int selectedDay = -1, selectedMonth = -1, selectedYear = -1;

// -------------------------------------------------*/*---------------------------------------//
@SuppressLint("NewApi")
@Override
public void initialize() {
    myAppointment = (LinearLayout) inflater.inflate(
            R.layout.my_appointments_layout, null);
    llCalTop = (LinearLayout) myAppointment.findViewById(R.id.llCalTop);
    llBody.addView(myAppointment, new LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    appointmentsExpandableList = (ListView) findViewById(R.id.appointmentsExpandableList);
    ivHeaderRight = (ImageView) findViewById(R.id.ivHeaderRight);

    // initLists();

    vecRequestDOs = new MyAppointmentsDA()
            .getAllInitiativesById("31-01-2015");
    adapter = new AppointmentListAdapter(MyAppointment.this, vecRequestDOs);
    header.setText("My Appointment");
    appointmentsExpandableList.setAdapter(adapter);
    ivHeaderRight.setVisibility(View.VISIBLE);
    ivHeaderRight.setImageResource(R.drawable.cal);

    ivHeaderRight.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (flag) {
                ivHeaderRight.setImageResource(R.drawable.list);
                flag = false;
                oldView = findViewById(R.id.llCalTop);
                //

                show();

            } else {
                ivHeaderRight.setImageResource(R.drawable.cal);
                flag = true;
                oldView = (LinearLayout) inflater.inflate(
                        R.layout.my_appointments_layout, null);
                llCalTop.setLayoutParams(new LinearLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT,
                        LayoutParams.MATCH_PARENT));
                llCalTop.removeAllViews();
                selectedDay = CustomCalendar.todayDate;
                selectedMonth = customCalender.month;
                selectedYear = customCalender.year;

                llCalTop.addView(oldView, new LayoutParams(
                        LayoutParams.MATCH_PARENT,
                        LayoutParams.MATCH_PARENT));
                sliderCalendar();

            }

        }
    });

    sliderCalendar();

}

@SuppressLint("NewApi")
public void show() {
    monthview = inflater.inflate(R.layout.monthview_cal, null);
    monthview.setLayoutParams(new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    llCalTop.removeAllViews();
    llCalTop.addView(monthview, new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT));
    context = MyAppointment.this;
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    CustomCalendar.CALENDER_CELL_WIDTH = width / 7;
    tvSelMonthYear = (TextView) findViewById(R.id.tvSelMonthYear);
    llcalBody = (LinearLayout) findViewById(R.id.llcalBody);
    tvPrevMonthClick = (TextView) findViewById(R.id.prevMonth);
    tvNextMonthClick = (TextView) findViewById(R.id.nextMonth);
    ivCalLeftArrow = (ImageView) findViewById(R.id.ivCalLeftArrow);
    ivCalRightArrow = (ImageView) findViewById(R.id.ivCalRightArrow);
    tvSelMonthYear.setTextSize(16);
    calendar = Calendar.getInstance();

    if (selectedDay != -1 && selectedMonth != -1 && selectedYear != -1) {
        calendar.set(selectedYear, selectedMonth, selectedDay);
    }

    month = calendar.get(Calendar.MONTH);
    year = calendar.get(Calendar.YEAR);

    CalPrev = Calendar.getInstance();
    CalPrev.add(Calendar.MONTH, -1);

    CalNext = Calendar.getInstance();
    CalNext.add(Calendar.MONTH, 1);

    tvSelMonthYear.setText(CalendarUtility.getMonth(month) + " "
            + calendar.get(Calendar.YEAR));
    showCalender(month, year);

    ivCalLeftArrow.setOnClickListener(this);
    ivCalRightArrow.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    if (v.getId() == R.id.ivCalLeftArrow) {
        calendar.add(Calendar.MONTH, -1);
        tvSelMonthYear.setText(CalendarUtility.getMonth(calendar
                .get(Calendar.MONTH)) + " " + calendar.get(Calendar.YEAR));
        setMonthText();
        showCalender(calendar.get(Calendar.MONTH),
                calendar.get(Calendar.YEAR));

    } else if (v.getId() == R.id.ivCalRightArrow) {

        calendar.add(Calendar.MONTH, +1);
        tvSelMonthYear.setText(CalendarUtility.getMonth(calendar
                .get(Calendar.MONTH)) + " " + calendar.get(Calendar.YEAR));
        showCalender(calendar.get(Calendar.MONTH),
                calendar.get(Calendar.YEAR));
        setMonthText();
    }
}

public void showCalender(int month, int year) {
    llcalBody.removeAllViews();
    customCalender = new CustomCalendar(context, month, year);
    llcalBody.addView(customCalender.makeCalendar(),
            LayoutParams.MATCH_PARENT);
}

public void setMonthText() {
    int tempCurrentMonth = calendar.get(Calendar.MONTH);
    if (tempCurrentMonth > 0 && tempCurrentMonth < 11) {
        tvPrevMonthClick.setText(CalendarUtility
                .getMonth(tempCurrentMonth - 1));
        tvNextMonthClick.setText(CalendarUtility
                .getMonth(tempCurrentMonth + 1));
    } else if (tempCurrentMonth == 0) {
        tvPrevMonthClick.setText(CalendarUtility.getMonth(11));
        tvNextMonthClick.setText(CalendarUtility.getMonth(1));
    } else if (tempCurrentMonth == 11) {
        tvPrevMonthClick.setText(CalendarUtility.getMonth(10));
        tvNextMonthClick.setText(CalendarUtility.getMonth(0));
    }
}

private void initLists() {
    // alist = new ArrayList<String>();
    // childs1 = new ArrayList<AppointmentDO>();
    // childs2 = new ArrayList<AppointmentDO>();
    // childs3 = new ArrayList<AppointmentDO>();
    // alist.add("WED, JAN 28");
    // // alist.add("THU, JAN 29");
    // // alist.add("FRI, JAN 30");
    // childs1.add(new AppointmentDO("R.MOHAN REDDY", "address", "09:00 AM",
    // "40 minutes"));
    // // childs1.add(new AppointmentDO("KIRAN KATTA", "address",
    // "10:00 AM",
    // // "40 minutes"));
    // // childs1.add(new AppointmentDO("R.MOHAN REDDY", "address",
    // "11:00 AM",
    // // "40 minutes"));
    // childs2.add(new AppointmentDO("KIRAN KATTA", "address", "12:00 PM",
    // "40 minutes"));
    // childs2.add(new AppointmentDO("R.MOHAN REDDY", "address", "10:30 AM",
    // "40 minutes"));
    // childs3.add(new AppointmentDO("KIRAN KATTA", "address", "10:45 AM",
    // "40 minutes"));
    // map = new HashMap<String, ArrayList<AppointmentDO>>();
    // map.put(alist.get(0), childs1);
    // map.put(alist.get(1), childs2);
    // map.put(alist.get(2), childs3);

}

protected void sliderCalendar() {
    // ---------------------------------Slider Calendar Implementation
    // -------------------------------------------//

    llCalTop = (LinearLayout) myAppointment.findViewById(R.id.llCalTop);

    lvItems = (HorizontialListView) myAppointment
            .findViewById(R.id.lvItems);
    tvMonth = (TextView) myAppointment.findViewById(R.id.tvMonth);
    ivleft = (ImageView) myAppointment.findViewById(R.id.ivleft);
    ivright = (ImageView) myAppointment.findViewById(R.id.ivright);

    commonBL = new CommonBL(MyAppointment.this, MyAppointment.this);

    cal = Calendar.getInstance();

    if (selectedDay != -1 && selectedMonth != -1 && selectedYear != -1) {
        cal.set(selectedYear, selectedMonth, selectedDay);
    }

    if (lvItems.getAdapter() == null) {
        calendarAdapter = new CalendarAdapter(MyAppointment.this, cal);
        calendarAdapter.setSelectedPosition(selectedDay - 1);

        lvItems.setAdapter(calendarAdapter);
        tvMonth.setText(CalendarUtils.getMonthFromNumber(cal
                .get(Calendar.MONTH) + 1));
        // /// -----------------Trying to scroll at selected date ---------------------//
        // ---------------/////
        lvItems.scrollTo((selectedDay - 1) * (60)
                + (lvItems.getChildCount() - (selectedDay - 1)));

        } else {
            calendarAdapter.notifyDataSetChanged();
        }

    // --------------------**--------------------------------------//

    lvItems.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View view,
                int position, long arg3) {
            appointmentdate = "";
            calendarAdapter.setSelectedPosition(position);
            // ----------------------**----------------//
            selectedDay = position;
            selectedMonth = cal.get(Calendar.MONTH);
            selectedYear = cal.get(Calendar.YEAR);
            Toast.makeText(getApplicationContext(),
                    selectedDay + "/" + selectedMonth + "/" + selectedYear,
                    Toast.LENGTH_SHORT).show();
            LogUtils.errorLog(
                    "Clicked Date",
                    (position + 1)
                            + ""
                            + CalendarUtils.getMonthFromNumber(cal
                                    .get(Calendar.MONTH) + 1) + ","
                            + cal.get(Calendar.YEAR));

            if (cal.get(Calendar.MONTH) + 1 < 10)
                appointmentdate = (position + 1) + "-0"
                        + (cal.get(Calendar.MONTH) + 1) + "-"
                        + cal.get(Calendar.YEAR);
            else
                appointmentdate = (position + 1) + "-"
                        + (cal.get(Calendar.MONTH) + 1) + "-"
                        + cal.get(Calendar.YEAR);
        }
    });

    ivleft.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            cal.add(Calendar.MONTH, -1);
            tvMonth.setText(CalendarUtils.getMonthFromNumber(cal
                    .get(Calendar.MONTH) + 1)
                    + " "
                    + cal.get(Calendar.YEAR));
            calendarAdapter.refresh(cal);
            calendarAdapter.setSelectedPosition(0);

        }
    });

    ivright.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            cal.add(Calendar.MONTH, 1);
            tvMonth.setText(CalendarUtils.getMonthFromNumber(cal
                    .get(Calendar.MONTH) + 1)
                    + " "
                    + cal.get(Calendar.YEAR));
            calendarAdapter.refresh(cal);
            calendarAdapter.setSelectedPosition(0);
        }
    });

    // --------------------------------------/**/--------------------------------------------------//
}

private class CalendarAdapter extends BaseAdapter {

    private String week[] = { "Su", "M", "T", "W", "Th", "F", "S" };
    private Context context;
    private int seletedPosition;
    private Calendar cal;

    public CalendarAdapter(Context context, Calendar cal) {
        this.cal = cal;
        this.context = context;
    }

    @Override
    public int getCount() {
        return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    public void setSelectedPosition(int seletedPosition) {
        this.seletedPosition = seletedPosition;
        notifyDataSetChanged();
    }

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

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

        ViewHolder viewHolder = new ViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.calendar_cell, null);
            viewHolder.tvweek = (TextView) convertView
                    .findViewById(R.id.tvweek);
            viewHolder.tvday = (TextView) convertView
                    .findViewById(R.id.tvday);
            convertView.setTag(viewHolder);
        } else
            viewHolder = (ViewHolder) convertView.getTag();

        viewHolder.tvday.setText((position + 1) + "");

        cal.set(Calendar.DAY_OF_MONTH, position + 1);

        viewHolder.tvweek
                .setText(week[cal.get(Calendar.DAY_OF_WEEK) - 1 % 7]);

        if (seletedPosition == position) {
            viewHolder.tvday.setBackgroundResource(R.drawable.date_hover);
            viewHolder.tvday.setTextColor(getResources().getColor(
                    R.color.white_color));
        } else {
            viewHolder.tvday.setBackgroundResource(0);
            viewHolder.tvday.setTextColor(getResources().getColor(
                    R.color.date_color));
        }

        return convertView;
    }

    public void refresh(Calendar cal) {
        this.cal = cal;
        notifyDataSetChanged();
    }

}

private static class ViewHolder {
    public TextView tvweek, tvday;
}

@Override
public void dataRetreived(Response data) {
    if (data.data != null) {
        if (data.method == ServiceMethods.WS_INSERT_REQUEST) {
            requestDO = (RequestDO) data.data;

            if (requestDO != null) {
                LogUtils.errorLog("Data Came", requestDO.Reason);
            }
        }
    }
}