Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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
Android 适配器。移除(标签); //更新列表 notifyDataChanged(); } }); alert.setNegativeButton(“否”, 新建DialogInterface.OnClickListener(){ @凌驾 public void onClick(DialogInterface dialog,int which){ //什么也没发生,孩子还在 } }); alert.show(); 返回true; } } @凌驾 public void addListItem(int itemId){ Label-labelToAdd=Label.lookupLabel(itemId); if(labelToAdd==null){ Log.e(标签“未找到标签id的标签”+itemId); }否则{ Log.e(标记,“添加标签:“+LabelLoadd.getLabel()+”) +labelLoadd.getId()+“id参数:”+itemId); //断开,因为适配器当前为字符串 适配器。添加(LabelLoadd); notifyDataChanged(); } } @凌驾 public void removeListItem(int itemId){ //TODO自动生成的方法存根 } @凌驾 公共无效删除项(){ //TODO自动生成的方法存根 } @凌驾 public void highlightListIndex(整数索引){ ListView ListView=getListView(); setItemChecked(索引,true); } }_Android - Fatal编程技术网

Android 适配器。移除(标签); //更新列表 notifyDataChanged(); } }); alert.setNegativeButton(“否”, 新建DialogInterface.OnClickListener(){ @凌驾 public void onClick(DialogInterface dialog,int which){ //什么也没发生,孩子还在 } }); alert.show(); 返回true; } } @凌驾 public void addListItem(int itemId){ Label-labelToAdd=Label.lookupLabel(itemId); if(labelToAdd==null){ Log.e(标签“未找到标签id的标签”+itemId); }否则{ Log.e(标记,“添加标签:“+LabelLoadd.getLabel()+”) +labelLoadd.getId()+“id参数:”+itemId); //断开,因为适配器当前为字符串 适配器。添加(LabelLoadd); notifyDataChanged(); } } @凌驾 public void removeListItem(int itemId){ //TODO自动生成的方法存根 } @凌驾 公共无效删除项(){ //TODO自动生成的方法存根 } @凌驾 public void highlightListIndex(整数索引){ ListView ListView=getListView(); setItemChecked(索引,true); } }

Android 适配器。移除(标签); //更新列表 notifyDataChanged(); } }); alert.setNegativeButton(“否”, 新建DialogInterface.OnClickListener(){ @凌驾 public void onClick(DialogInterface dialog,int which){ //什么也没发生,孩子还在 } }); alert.show(); 返回true; } } @凌驾 public void addListItem(int itemId){ Label-labelToAdd=Label.lookupLabel(itemId); if(labelToAdd==null){ Log.e(标签“未找到标签id的标签”+itemId); }否则{ Log.e(标记,“添加标签:“+LabelLoadd.getLabel()+”) +labelLoadd.getId()+“id参数:”+itemId); //断开,因为适配器当前为字符串 适配器。添加(LabelLoadd); notifyDataChanged(); } } @凌驾 public void removeListItem(int itemId){ //TODO自动生成的方法存根 } @凌驾 公共无效删除项(){ //TODO自动生成的方法存根 } @凌驾 public void highlightListIndex(整数索引){ ListView ListView=getListView(); setItemChecked(索引,true); } },android,Android,在滚动视图中,android不是滚动视图的最佳选择,就像您的情况一样。 您必须尝试避免这种情况,尝试修改布局以避免这些冲突 A**方法中的一个难题是,当用户在listfragment上滚动时,拦截家长的触摸事件(也添加一个手势侦听器),并将事件传递给listfragment(您必须知道屏幕内片段的坐标等)。这听起来很容易,然后是因为它会导致很多问题,所以我建议重写您的布局,而不是 <?xml version="1.0" encoding="utf-8"?> <Scrol

在滚动视图中,android不是滚动视图的最佳选择,就像您的情况一样。 您必须尝试避免这种情况,尝试修改布局以避免这些冲突

A**方法中的一个难题是,当用户在listfragment上滚动时,拦截家长的触摸事件(也添加一个手势侦听器),并将事件传递给listfragment(您必须知道屏幕内片段的坐标等)。这听起来很容易,然后是因为它会导致很多问题,所以我建议重写您的布局,而不是

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/new_interval_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="New Interval" />

        <EditText
            android:id="@+id/days_in_interval"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="days in interval"
            android:inputType="number"
            android:singleLine="true" />

        <EditText
            android:id="@+id/goodi_goal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:hint="goodi goal"
            android:inputType="number"
            android:singleLine="true" />

        <LinearLayout
            android:id="@+id/label_selector"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <LinearLayout
                android:id="@+id/default_label_pane"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Default Labels" />

                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="fill_parent"
                    android:scrollbars="vertical" >

                    <fragment
                        xmlns:android="http://schemas.android.com/apk/res/android"
                        android:id="@+id/default_labels_fragment"
                        android:name="com.chex.control.LabelList"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@android:color/white"
                        android:focusable="true" >
                    </fragment>
                </ScrollView>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/add_remove_label_selector"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" >

                <Button
                    android:id="@+id/add_label_button"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Add" />

                <Button
                    android:id="@+id/remove_label_button"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Remove" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/label_pane"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Inteval Labels" />

                <fragment
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/interval_labels_fragment"
                    android:name="com.chex.control.IntervalLabelList"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:focusable="true" >
                </fragment>

                <EditText
                    android:id="@+id/new_label"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:hint="new label"
                    android:inputType="text"
                    android:singleLine="true" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/keep_discard_button_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/keep_interval_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Keep" />

            <Button
                android:id="@+id/discard_interval_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Discard" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>
package com.chex.control;


import java.util.ArrayList;

import com.chex.R;
import com.chex.storage.Child;
import com.chex.storage.DatabaseConstants;
import com.chex.storage.DatabaseHelper;
import com.chex.storage.DatabaseIO;
import com.chex.storage.Label;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
 * presents all the labels on the device.
 */
public class LabelList extends ListFragment implements DatabaseConstants,
        GoodiList {

    private final String TAG = "LabelList";

    ArrayAdapter<Label> adapter = null;

    private ListParent parentActivity;

    private Label[] values;

    private Label currentItem;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Log.e(TAG, "on Create");
        ArrayList<Label> labelList = Label.getLabelsForInterval();

        Log.i(TAG,labelList.size()+" labels");
        // adapter = new IntervalListAdapter(getActivity(), values);

        adapter = new IntervalListAdapter(getActivity(), labelList);

        setListAdapter(adapter);

        Log.e(TAG, "finished on Create");
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
     */
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);

        LongClickListener longClickListener = new LongClickListener();

        getListView().setOnItemLongClickListener(longClickListener);
    }

    /**
     * create and return a CursorLoader that will take care of creating a Curso
     * for the data being displayed.
     */

    /**
     * this used to delete. However, we need it to select usually. Now delete is
     * done by long click.
     */
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);

        // delete child - remove child from list and database
        Object item = l.getItemAtPosition(position);

        currentItem = (Label) item;

        Log.e(TAG,
                "selected " + currentItem.getLabel() + " id: "
                        + currentItem.getId() + " at position " + position);

        parentActivity.listItemSelected(this, position, currentItem.getId());

    }

    /**
     * Forces cursor to requery database and list to be update. Used when a new
     * child is entered in parent activity's EditText field.
     */
    public void notifyDataChanged() {

        Log.e(TAG, "told adapter that data changed");

        adapter.notifyDataSetChanged();
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
     */
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        parentActivity = (ListParent) activity;

        parentActivity.setList(this);

    }

    class LongClickListener implements OnItemLongClickListener {

        public boolean onItemLongClick(AdapterView<?> adapterView, View view,
                int position, long id) {
            // delete child - remove child from list and database

            // adapter view. Can always call parent's getItemAtPosition
            final Object item = adapterView.getItemAtPosition(position);

            final Label label = (Label) item;

            final String name = label.getLabel();

            Log.e(TAG, "selected " + name + " at position " + position
                    + " now we'll delete them");

            // make sure user wants to delete
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

            alert.setTitle("Delete " + name + "?");

            alert.setPositiveButton("Yes",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Label.deleteLabel(name);

                            adapter.remove(label);

                            // update the list
                            notifyDataChanged();

                        }
                    });

            alert.setNegativeButton("No",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            // nothing happens - child remains

                        }
                    });

            alert.show();

            return true;
        }

    }

    @Override
    public void addListItem(int itemId) {
        Label labelToAdd = Label.lookupLabel(itemId);

        if (labelToAdd == null) {
            Log.e(TAG, "didn't find a label for label id " + itemId);

        } else {
            Log.e(TAG, "adding label: " + labelToAdd.getLabel() + "  "
                    + labelToAdd.getId() + "  id argument: " + itemId);

            // breaks because the adapter is currently strings
            adapter.add(labelToAdd);

            notifyDataChanged();
        }
    }

    @Override
    public void removeListItem(int itemId) {
        // TODO Auto-generated method stub

    }

    @Override
    public void removeListItem() {
        // TODO Auto-generated method stub

    }


    @Override
    public void highlightListIndex(int index) {
        ListView listView = getListView();
        listView.setItemChecked(index, true);
    }

}