无法处理ListView

时间:2012-10-15 03:52:18

标签: android

在我的ListView中,该项目有Switch个活动。当项目溢出屏幕时,必须滑动显示顶部或底部项目。然后,顶部或底部的项目切换将自动更改状态和响应状态事件更改。屏幕后面隐藏的项目越多,越多变化发生。我不知道如何解决

有没有人可以提供帮助?非常感谢。

我已更新

上的代码

private class MAdapter extends CursorAdapter
{
    private Context context;
    private LayoutInflater mInflater;

    public MAdapter(Context context, Cursor c)
    {
        super(context, c, true);

        this.context = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent)
    {
        View v = mInflater.inflate(R.layout.main_task_list_item, null);
        return v;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor)
    {
        final MZTask task = new MZTask(cursor);

        // ic
        ImageView ic = (ImageView) view
                .findViewById(R.id.main_list_action_ic);
        ic.setImageResource(task.getIcId());

        // action name
        TextView actionName = (TextView) view
                .findViewById(R.id.main_list_action_name);
        actionName.setText(task.getActionName(context));

        // time
        TextView time = (TextView) view
                .findViewById(R.id.main_list_task_time);
        time.setText(task.getTimeString());

        // repeat
        TextView repeat = (TextView) view
                .findViewById(R.id.main_list_task_repeat);
        repeat.setText(task.getDayStringOfWeek(context));

        // switch view
        final Switch stch = (Switch) view
                .findViewById(R.id.main_list_task_switch);
        stch.setOnCheckedChangeListener(getCheckedChangeListener(task));
        stch.setChecked(task.state());

        // list more
        RelativeLayout icLayout = (RelativeLayout) view
                .findViewById(R.id.main_list_more);
        icLayout.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
            {
                popUpMenu(task);
            }
        });

        // ..
        RelativeLayout itemLayout = (RelativeLayout) view
                .findViewById(R.id.main_list_layout_switch);
        itemLayout.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
            {
                stch.setChecked(!stch.isChecked());
            }
        });

    }

    public OnCheckedChangeListener getCheckedChangeListener(
            final MZTask task)
    {
        return new OnCheckedChangeListener()
        {
            public void onCheckedChanged(CompoundButton button,
                    boolean change)
            {
                if (change)
                    task.startTask(context, dbAdapter);
                else
                    task.cancelTask(context, dbAdapter);
            }
        };
    }

}

0 个答案:

没有答案