Java Code Examples for android.widget.ListView#setOnTouchListener()

The following examples show how to use android.widget.ListView#setOnTouchListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: GravityBox   File: QsDetailItemsList.java    License: Apache License 2.0 6 votes vote down vote up
private QsDetailItemsList(LinearLayout view) {
    mView = view;

    mListView = (ListView) mView.findViewById(android.R.id.list);
    mListView.setOnTouchListener(new OnTouchListener() {
        // Setting on Touch Listener for handling the touch inside ScrollView
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Disallow the touch request for parent scroll on touch of child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });
    mEmpty = mView.findViewById(android.R.id.empty);
    mEmpty.setVisibility(View.GONE);
    mEmptyText = (TextView) mEmpty.findViewById(android.R.id.title);
    mEmptyIcon = (ImageView) mEmpty.findViewById(android.R.id.icon);
    mListView.setEmptyView(mEmpty);
}
 
Example 2
Source Project: Shield   File: AgentMapListActivity.java    License: MIT License 6 votes vote down vote up
private void initListView() {
    listView = new ListView(this);
    listView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    hideKeyboard(searchBtnText);
            }
            return false;
        }
    });
    agentMapAdapter = new AgentMapAdapter(getApplicationContext(), listViewList);
    listView.setAdapter(agentMapAdapter);
    searchContent.addView(listView);
    this.listViewList.clear();
}
 
Example 3
private void init() {
        listView = (ListView) findViewById(R.id.list_view);

        String[] strs = getData(100);
        List<Map<String, Object>> list = new ArrayList<>();
        for (String str : strs) {
            Map<String, Object> map = new HashMap<>();
            map.put("text", str);
            list.add(map);
        }
        SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.item_simple, new String[]{"text"}, new int[]{R.id.text_view});
        listView.setAdapter(adapter);

        AutoScrollHelper autoScrollHelper = new ListViewAutoScrollHelper(listView);
        listView.setOnTouchListener(autoScrollHelper);
        autoScrollHelper.setEnabled(true);
//        autoScrollHelper.setActivationDelay(3000);
//        autoScrollHelper.setRampDownDuration(3000);
        Toast.makeText(this, "长按上或下边缘", Toast.LENGTH_SHORT).show();
    }
 
Example 4
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_search_static_list, container, false);
    ListView listView = (ListView) rootView.findViewById(R.id.search_static_list);
    ArrayList<String> strings = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        strings.add(i+" -- \n"+getString(R.string.lorem_1));
    }
    ListViewAdapter adapter = new ListViewAdapter(getActivity(), strings);
    listView.setAdapter(adapter);
    listView.setOnTouchListener(new View.OnTouchListener() {
        // Setting on Touch Listener for handling the touch inside ScrollView
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Disallow the touch request for parent scroll on touch of child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });
    return rootView;
}
 
Example 5
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_search_static_list, container, false);
    ListView listView = (ListView) rootView.findViewById(R.id.search_static_list);
    ArrayList<String> strings = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        strings.add(i+" -- \n"+getString(R.string.lorem_1));
    }
    ListViewAdapter adapter = new ListViewAdapter(getActivity(), strings);
    listView.setAdapter(adapter);
    listView.setOnTouchListener(new View.OnTouchListener() {
        // Setting on Touch Listener for handling the touch inside ScrollView
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Disallow the touch request for parent scroll on touch of child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });
    return rootView;
}
 
Example 6
Source Project: LoveTalkClient   File: ContactFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void initListView() {
	friendsList = (ListView) getView().findViewById(R.id.list_friends);
	LayoutInflater mInflater = LayoutInflater.from(context);
	RelativeLayout headView = (RelativeLayout) mInflater.inflate(
			R.layout.contact_include_new_friend, null);
	msgTipsView = (ImageView) headView.findViewById(R.id.iv_msg_tips);
	newFriendLayout = (LinearLayout) headView.findViewById(R.id.layout_new);


	newFriendLayout.setOnClickListener(this);

	friendsList.addHeaderView(headView);
	userAdapter = new UserFriendAdapter(getActivity(), friends);
	friendsList.setAdapter(userAdapter);
	friendsList.setOnItemClickListener(this);
	friendsList.setOnItemLongClickListener(this);
	friendsList.setOnTouchListener(new OnTouchListener() {

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			Utils.hideSoftInputView(getActivity());
			return false;
		}
	});
}
 
Example 7
Source Project: AndroidHeros   File: ScrollHideListView.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scroll_hide);
    mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mListView = (ListView) findViewById(R.id.listview);
    for (int i = 0; i < mStr.length; i++) {
        mStr[i] = "Item " + i;
    }
    View header = new View(this);
    // abc_action_bar_default_height_material 获取系统ActionBar的高度
    header.setLayoutParams(new AbsListView.LayoutParams(
            AbsListView.LayoutParams.MATCH_PARENT,
            (int) getResources().getDimension(
                    R.dimen.abc_action_bar_default_height_material)));
    mListView.addHeaderView(header);
    mListView.setAdapter(new ArrayAdapter<String>(
            ScrollHideListView.this,
            android.R.layout.simple_expandable_list_item_1,
            mStr));
    mListView.setOnTouchListener(myTouchListener);
}
 
Example 8
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recognition);

    readBundle(savedInstanceState);
    mListView = (ListView) findViewById(R.id.list);
    mAdapter = new SpeechAdapter(this, mSpeechDatas);
    mListView.setAdapter(mAdapter);
    mListView.setOnTouchListener(mOnTouchListener);
    findViewById(R.id.container).setOnTouchListener(mOnTouchListener);

    mStatusText = (TextView) findViewById(R.id.lbl_status);
    mSliderView = (SliderView) findViewById(R.id.indeterm_slider);

    if (App.runningOnGoogleGlass()) {
        mGestureDetector = new GestureDetector(this);
        mGestureDetector.setAlwaysConsumeEvents(true);
        mGestureDetector.setBaseListener(mBaseListener);
        mGestureDetector.setScrollListener(mScrollListener);
        mGestureDetector.setFingerListener(mFingerListener);
    }

    setStatus(R.string.recog_tap_and_hold);
}
 
Example 9
Source Project: opentasks   File: FlingDetector.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a new {@link FlingDetector} for the given {@link ListView}.
 *
 * @param listview
 *         The {@link ListView}.
 * @param flingContentViewId
 *         The layout id of the inner content view that is supposed to fling
 */
public FlingDetector(ListView listview, int flingContentViewId)
{
    listview.setOnTouchListener(this);
    listview.setOnScrollListener(this);
    mListView = listview;
    mContentViewId = flingContentViewId;

    ViewConfiguration vc = ViewConfiguration.get(listview.getContext());

    mTouchSlop = vc.getScaledTouchSlop();

    mMinimumFlingVelocity = vc.getScaledMinimumFlingVelocity() * 8; // we want the user to fling harder!
    mMaximumFlingVelocity = vc.getScaledMaximumFlingVelocity() * 8;

    mHandler = new Handler();
}
 
Example 10
Source Project: tickmate   File: Tickmate.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_tickmate_list);

       RelativeLayout progress = new RelativeLayout(this);
       progress.setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.MATCH_PARENT, 100));
       progress.setGravity(Gravity.CENTER);
       progress.addView(new ProgressBar(this));

       mAdapter = new InfiniteScrollAdapter<>(this,
               new TickAdapter(this, null, savedInstanceState), progress);
       mAdapter.addListener(this);

       mHandler = new Handler();

       mListHeader = (TickHeader) findViewById(R.id.list_header);
       mListHeader.initialize(this);

       mListView = (ListView) findViewById(android.R.id.list);
       mListView.setStackFromBottom(true);
       mListView.setAdapter(mAdapter);
       mListView.setOnTouchListener(mListHeader);
       mListView.getEmptyView().setOnClickListener(this);
       mListView.getEmptyView().setOnTouchListener(mListHeader);
}
 
Example 11
private void initListView(){
	listView = (ListView) findViewById(R.id.messageListview);
	
	//create Data
	Message message = new Message(Message.MSG_TYPE_TEXT, Message.MSG_STATE_SUCCESS, "Tom", "avatar", "Jerry", "avatar", "Hi", false, true, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * 8));
	Message message1 = new Message(Message.MSG_TYPE_TEXT, Message.MSG_STATE_SUCCESS, "Tom", "avatar", "Jerry", "avatar", "Hello World", true, true, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)* 8));
	Message message2 = new Message(Message.MSG_TYPE_PHOTO, Message.MSG_STATE_SUCCESS, "Tom", "avatar", "Jerry", "avatar", "device_2014_08_21_215311", false, true, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * 7));
	Message message3 = new Message(Message.MSG_TYPE_TEXT, Message.MSG_STATE_SUCCESS, "Tom", "avatar", "Jerry", "avatar", "Haha", true, true, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * 7));
	Message message4 = new Message(Message.MSG_TYPE_FACE, Message.MSG_STATE_SUCCESS, "Tom", "avatar", "Jerry", "avatar", "big3", false, true, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * 7));
	Message message5 = new Message(Message.MSG_TYPE_FACE, Message.MSG_STATE_SUCCESS, "Tom", "avatar", "Jerry", "avatar", "big2", true, true, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * 6));
	Message message6 = new Message(Message.MSG_TYPE_TEXT, Message.MSG_STATE_FAIL, "Tom", "avatar", "Jerry", "avatar", "test send fail", true, false, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * 6));
	Message message7 = new Message(Message.MSG_TYPE_TEXT, Message.MSG_STATE_SENDING, "Tom", "avatar", "Jerry", "avatar", "test sending", true, true, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * 6));
	
	List<Message> messages = new ArrayList<Message>();
	messages.add(message);
	messages.add(message1);
	messages.add(message2);
	messages.add(message3);
	messages.add(message4);
	messages.add(message5);
	messages.add(message6);
	messages.add(message7);
	
	adapter = new MessageAdapter(this, messages);
	listView.setAdapter(adapter);
	adapter.notifyDataSetChanged();
	
	listView.setOnTouchListener(new OnTouchListener() {
		@Override
		public boolean onTouch(View v, MotionEvent event) {
			box.hide();
			return false;
		}
	});
	
}
 
Example 12
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (!receiverRegistered) {
        receiverRegistered = true;
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
        filter.addAction(Intent.ACTION_MEDIA_CHECKING);
        filter.addAction(Intent.ACTION_MEDIA_EJECT);
        filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        filter.addAction(Intent.ACTION_MEDIA_NOFS);
        filter.addAction(Intent.ACTION_MEDIA_REMOVED);
        filter.addAction(Intent.ACTION_MEDIA_SHARED);
        filter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
        filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        filter.addDataScheme("file");
        getParentActivity().registerReceiver(receiver, filter);
    }


    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.document_select_layout, container, false);
        fragmentView.setPadding(0, (int) getResources().getDimension(R.dimen.actionbar_height), 0, 0);
        listAdapter = new ListAdapter(parentActivity);
        emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        listView = (ListView) fragmentView.findViewById(R.id.listView);
        listView.setEmptyView(emptyView);
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ListItem item = items.get(i);
                File file = item.file;
                if (file.isDirectory()) {
                    HistoryEntry he = new HistoryEntry();
                    he.scrollItem = listView.getFirstVisiblePosition();
                    he.scrollOffset = listView.getChildAt(0).getTop();
                    he.dir = currentDir;
                    ActionBar actionBar = parentActivity.getSupportActionBar();
                    he.title = actionBar.getTitle().toString();
                    if (!listFiles(file)) {
                        return;
                    }
                    history.add(he);
                    actionBar.setTitle(item.title);
                    listView.setSelection(0);
                } else {
                    if (!file.canRead()) {
                        showErrorBox(getString(R.string.AccessError));
                        return;
                    }
                    if (sizeLimit != 0) {
                        if (file.length() > sizeLimit) {
                            showErrorBox(getString(R.string.FileUploadLimit, Utilities.formatFileSize(sizeLimit)));
                            return;
                        }
                    }
                    if (file.length() == 0) {
                        return;
                    }
                    if (delegate != null) {
                        delegate.didSelectFile(DocumentSelectActivity.this, file.getAbsolutePath());
                    }
                }
            }
        });

        listView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
            }
        });
        listRoots();
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}
 
Example 13
/**
 * initialize ui/views
 * @param context a context used to access resources
 */
protected void initViews(Context context)
{
    SuntimesUtils.initDisplayStrings(context);

    Toolbar menuBar = (Toolbar) findViewById(R.id.app_menubar);
    setSupportActionBar(menuBar);
    actionBar = getSupportActionBar();

    if (actionBar != null)
    {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        boolean showBack = getIntent().getBooleanExtra(EXTRA_SHOWBACK, false);
        if (!showBack) {
            actionBar.setHomeAsUpIndicator(R.drawable.ic_action_suntimes);
        }
    }

    addButton = (FloatingActionButton) findViewById(R.id.btn_add);
    addButton.setBackgroundTintList(SuntimesUtils.colorStateList(colorAlarmEnabled, colorDisabled, colorPressed));
    addButton.setRippleColor(Color.TRANSPARENT);
    addButton.setOnClickListener(onFabMenuClick);

    addAlarmButtonLayout = findViewById(R.id.layout_btn_addAlarm);
    addAlarmButton = (FloatingActionButton) findViewById(R.id.btn_addAlarm);
    addAlarmButton.setBackgroundTintList(SuntimesUtils.colorStateList(colorPressed, colorDisabled, colorAlarmEnabled));
    addAlarmButton.setRippleColor(Color.TRANSPARENT);
    addAlarmButton.setOnClickListener(onAddAlarmButtonClick);

    addNotificationButtonLayout = findViewById(R.id.layout_btn_addNotification);
    addNotificationButton = (FloatingActionButton) findViewById(R.id.btn_addNotification);
    addNotificationButton.setBackgroundTintList(SuntimesUtils.colorStateList(colorPressed, colorDisabled, colorAlarmEnabled));
    addNotificationButton.setRippleColor(Color.TRANSPARENT);
    addNotificationButton.setOnClickListener(onAddNotificationButtonClick);

    collapseFabMenu();

    alarmList = (ListView)findViewById(R.id.alarmList);
    alarmList.setOnItemClickListener(onAlarmItemClick);
    alarmList.setOnTouchListener(new View.OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            int pos = alarmList.pointToPosition((int)event.getX(), (int)event.getY());
            if ((event.getAction() == MotionEvent.ACTION_DOWN) && pos == -1) {
                collapseFabMenu();
                setSelectedItem(-1);
            }
            return false;
        }
    });

    emptyView = findViewById(android.R.id.empty);
    emptyView.setOnClickListener(onEmptyViewClick);
}
 
Example 14
private void initialize(View rootView) {
  setHasOptionsMenu(true);
  mGroupIdQueue = new ArrayList<>();
  mHandler = new Handler();

  mSwipeRefreshWidget = (SwipeRefreshWidget) rootView.findViewById(R.id.swipe_refresh_widget);
  mSwipeRefreshWidget.setColorSchemeResources(R.color.swipe_refresh_widget_first_color,
                                              R.color.swipe_refresh_widget_second_color);
  mSwipeRefreshWidget.setOnRefreshListener(this);

  getActivity().getActionBar().setTitle(R.string.title_nearby_beacons);
  mNearbyDeviceAdapter = new NearbyBeaconsAdapter();
  setListAdapter(mNearbyDeviceAdapter);
  //Get the top drawable
  mScanningAnimationTextView = (TextView) rootView.findViewById(android.R.id.empty);
  mScanningAnimationDrawable =
      (AnimationDrawable) mScanningAnimationTextView.getCompoundDrawables()[1];
  ListView listView = (ListView) rootView.findViewById(android.R.id.list);
  mDiscoveryServiceConnection = new DiscoveryServiceConnection();
  mWifiDirectConnect = new WifiDirectConnect(getActivity());
  mBluetoothSite = new BluetoothSite(getActivity());
  mTouchListener =
    new SwipeDismissListViewTouchListener(
            listView,
            new SwipeDismissListViewTouchListener.DismissCallbacks() {
                @Override
                public boolean canDismiss(int position) {
                    return true;
                }

                @Override
                public void onDismiss(ListView listView, int position) {
                  Utils.addBlocked(mNearbyDeviceAdapter.getItem(position));
                  Utils.saveBlocked(getActivity());
                  if (mMissedEmptyGroupIdQueue) {
                    mMissedEmptyGroupIdQueue = false;
                    emptyGroupIdQueue();
                  }
                }
            });
  listView.setOnTouchListener(mTouchListener);

  // Setting this scroll listener is required to ensure that during ListView scrolling,
  // we don't look for swipes.
  listView.setOnScrollListener(mTouchListener.makeScrollListener());
  Utils.restoreFavorites(getActivity());
  Utils.restoreBlocked(getActivity());
}
 
Example 15
Source Project: ghwatch   File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Log.d(TAG, "onCreate() intent: " + getIntent());

  if (savedInstanceState != null) {
    filterByRepository = savedInstanceState.getString(STATE_FILTER_REPOSITORY);
  }

  setContentView(R.layout.activity_main);

  imageLoader = ImageLoader.getInstance(getApplicationContext());
  unreadNotificationsService = new UnreadNotificationsService(getBaseContext());

  initNavigationDrawer(R.id.nav_unread);

  repositoriesListViewTablet = (ListView) findViewById(R.id.repositories_list);
  if (repositoriesListViewTablet != null)
    repositoriesListViewTablet.setOnItemClickListener(new RepositoriesListItemClickListener());

  // initialization of main content
  notificationsListView = (ListView) findViewById(R.id.list);
  notificationsListView.setVerticalFadingEdgeEnabled(true);
  SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(notificationsListView, new NotificationsListSwipeDismissListener());
  notificationsListView.setOnTouchListener(touchListener);
  // Setting this scroll listener is required to ensure that during ListView scrolling,
  // we don't look for swipes.
  notificationsListView.setOnScrollListener(touchListener.makeScrollListener());

  Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbar_bottom);
  if (toolbarBottom != null) {
    toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
      @Override
      public boolean onMenuItemClick(MenuItem item) {
        return onOptionsItemSelected(item);
      }
    });
    if (repositoriesListViewTablet == null)
      toolbarBottom.inflateMenu(R.menu.main_activity_toolbar);
    else
      toolbarBottom.inflateMenu(R.menu.main_activity_toolbar_tablet);

  }

  initSwipeLayout(this);
}