Example usage for android.widget AdapterView getChildCount

List of usage examples for android.widget AdapterView getChildCount

Introduction

In this page you can find the example usage for android.widget AdapterView getChildCount.

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

From source file:Main.java

public static View getItemViewIfVisible(AdapterView<?> holder, int itemPos) {
    int firstPosition = holder.getFirstVisiblePosition();
    int wantedChild = itemPos - firstPosition;
    if (wantedChild < 0 || wantedChild >= holder.getChildCount())
        return null;
    return holder.getChildAt(wantedChild);
}

From source file:foundme.uniroma2.it.professore.ReadMessageActivity.java

public static void populateView(String[] result) {
    messageIds = new String[result.length];
    List<Map<String, String>> data = new ArrayList<Map<String, String>>();

    for (int i = 0; i < result.length; i++) {
        Map<String, String> datum = new HashMap<String, String>(2);
        if (i == 0 && result[0].equalsIgnoreCase(Variables_it.NO_MSG)) {
            datum.put("Msg", result[0]);
            datum.put("Num", "");
            data.add(datum);/*from www.  ja  va  2 s  .  c  om*/
            messageIds[0] = result[0];
            break;
        } else {
            String[] items = result[i].split(",");
            String ap = "[" + items[0] + "] " + items[1];
            datum.put("Msg", ap);
            datum.put("Num", "Messaggio Visualizzato: " + items[2] + " volte");
            data.add(datum);
            messageIds[i] = items[3];
        }
    }
    //creo l'adapter
    SimpleAdapter adapter = new SimpleAdapter(context, data, android.R.layout.simple_list_item_2,
            new String[] { "Msg", "Num" }, new int[] { android.R.id.text1, android.R.id.text2 });
    //inserisco i dati
    lvMessaggi.setAdapter(adapter);

    swipeMsg.setColorSchemeColors(0xff429874, 0xffffffff, 0xff429874, 0xffffffff);
    swipeMsg.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            swipeMsg.setRefreshing(true);
            (new Handler()).postDelayed(new Runnable() {
                @Override
                public void run() {
                    swipeMsg.setRefreshing(false);
                    try {
                        getMsg(Title, false);
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, 3000);
        }
    });

    lvMessaggi.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
            toEdit = messageIds[position];
            for (int j = 0; j < parent.getChildCount(); j++)
                parent.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);

            view.setBackgroundColor(0xff429874);
            ((Activity) context).startActionMode(modeCallBack);
            viewList = view;
            return true;
        }
    });

    lvMessaggi.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            if (firstVisibleItem == 0)
                swipeMsg.setEnabled(true);
            else
                swipeMsg.setEnabled(false);
        }
    });
}

From source file:foundme.uniroma2.it.professore.HomeActivity.java

public static void populateView(String[] result) {

    courses = new String[result.length];
    System.arraycopy(result, 0, courses, 0, result.length);
    ArrayList<String> listp = new ArrayList<String>();

    Collections.addAll(listp, courses);
    //creo l'adapter
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1,
            listp);/*  w  w w. j  av  a2 s  . c o  m*/
    //inserisco i dati
    lvCourses.setAdapter(adapter);
    swipeView.setColorSchemeColors(0xff429874, 0xffffffff, 0xff429874, 0xffffffff);
    swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            swipeView.setRefreshing(true);
            (new Handler()).postDelayed(new Runnable() {
                @Override
                public void run() {
                    try {
                        getCourse(false);
                    } catch (ExecutionException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    swipeView.setRefreshing(false);
                }
            }, 3000);
        }
    });

    lvCourses.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            if (firstVisibleItem == 0)
                swipeView.setEnabled(true);
            else
                swipeView.setEnabled(false);
        }
    });

    lvCourses.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
            toEdit = courses[position];
            for (int j = 0; j < parent.getChildCount(); j++)
                parent.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);

            view.setBackgroundColor(0xff429874);
            ((Activity) context).startActionMode(modeCallBack);
            viewList = view;
            return true;
        }
    });

    lvCourses.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!courses[position].equalsIgnoreCase(Variables_it.NO_COURSE)) {
                Intent i = new Intent(context, CoursesActivity.class);
                i.putExtra(Variables_it.COURSE, courses[position]);
                i.putExtra(Variables_it.NAME, name);
                i.putExtra(Variables_it.ROOM, nfctest.getText().toString());
                context.startActivity(i);
            }
        }
    });
}

From source file:com.hodor.company.areminder.ui.MainActivity.java

private void initEvents() {
    this.mTineUnit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/*from  ww w . j  a  v a 2  s  .  co m*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            unit = (isChecked) ? units.HOURS : units.MINUTES;
            configureMaxValuePicker();
        }
    });
    this.mCategory.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String checkedName = mCategoriesAdapter.getItem(position).getName();
            category = (checkedName.equals(getString(R.string.category_food))) ? categories.FOOD
                    : (checkedName.equals(getString(R.string.category_work))) ? categories.WORK
                            : categories.SPORT;

            for (int i = 0; i < parent.getChildCount(); i++) {
                ((ImageView) parent.getChildAt(i).findViewById(R.id.picture))
                        .setColorFilter(ImagesUtil.getGrayScaleFilter());
                parent.getChildAt(i).setAlpha(0.4f);
            }
            ((ImageView) view.findViewById(R.id.picture)).clearColorFilter();
            view.setAlpha(1);
        }
    });
    this.stopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            stopChronometer();
            stopRemind(v);
            setEnableMainActivity(true);
        }
    });
    this.closeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setEnableMainActivity(true);
        }
    });
}

From source file:com.recyclerviewpulldownrefresh.view.refresh.AbPullToRefreshView.java

/**
 * ??/* w  ww  .  j  av  a 2 s  . c  o  m*/
 *
 * @return
 */
public boolean canChildScrollDown() {
    if (!mEnableLoadMore) {
        return false;
    }
    if (mTarget instanceof AdapterView<?>) {
        AdapterView<?> absListView = (AdapterView<?>) mTarget;
        View lastChild = absListView.getChildAt(absListView.getChildCount() - 1);
        if (lastChild == null) {
            return true;
        }
        // ??viewBottom?ViewmAdapterView?view,
        // ViewmAdapterView??
        if (lastChild.getBottom() <= getHeight()
                && absListView.getLastVisiblePosition() == absListView.getCount() - 1) {
            return true;
        }
    } else if (mTarget instanceof WebView) {
        WebView webview = (WebView) mTarget;
        return webview.getContentHeight() * webview.getScale() <= webview.getHeight() + webview.getScrollY();
    } else if (mTarget instanceof ScrollView) {
        ScrollView scrollView = (ScrollView) mTarget;
        View childView = scrollView.getChildAt(0);
        if (childView != null) {
            return childView.getMeasuredHeight() <= getHeight() + mScrollView.getScrollY();
        }
    } else if (mTarget instanceof RecyclerView) {
        int lastVisiblePosition = 0;
        View childView = null;

        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

        if (layoutManager instanceof LinearLayoutManager) {
            lastVisiblePosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            childView = layoutManager.findViewByPosition(lastVisiblePosition);
        } else if (layoutManager instanceof GridLayoutManager) {
            lastVisiblePosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            childView = layoutManager.findViewByPosition(lastVisiblePosition);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            int[] spanPosition = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
            ((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(spanPosition);
            lastVisiblePosition = getLastVisibleItemPosition(spanPosition);
            childView = getLastVisibleItemBottomView(layoutManager, spanPosition, lastVisiblePosition);
        }
        if (null == childView) {
            return false;
        }

        if (lastVisiblePosition == layoutManager.getItemCount() - 1 && childView.getBottom()
                + layoutManager.getBottomDecorationHeight(childView) <= mTarget.getBottom()) {
            return true;
        }
    } else {
        return ViewCompat.canScrollVertically(mTarget, 1);
    }
    return false;
}

From source file:org.gots.ui.NewSeedActivity.java

/**
*
*//*from   w w  w  .  j  a v a  2  s  . c  om*/
private void initSpecieList() {
    // final LocalSeedProvider helper = new LocalSeedProvider(getApplicationContext());
    new AsyncTask<Void, Void, String[]>() {
        @Override
        protected String[] doInBackground(Void... params) {
            String[] specieList = seedManager.getArraySpecies(true);
            return specieList;
        }

        @Override
        protected void onPostExecute(String[] specieList) {
            // TODO Auto-generated method stub
            ListSpeciesAdapter listSpeciesAdapter = new ListSpeciesAdapter(getApplicationContext(), specieList,
                    newSeed);
            gallerySpecies.setAdapter(listSpeciesAdapter);
            gallerySpecies.setSpacing(5);
            super.onPostExecute(specieList);
        }
    }.execute();

    gallerySpecies.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            gallerySpecies.dispatchSetSelected(false);
            if (((String) view.getTag()).equals(newSeed.getSpecie())) {
                // clicked already selected item
                return;
            }
            // Selected specie changed -> remove background on others
            for (int i = 0; i < parent.getChildCount(); i++) {
                View childView = parent.getChildAt(i);
                if (childView != view) {
                    childView.setBackgroundColor(0);
                }
            }
            view.setSelected(true);
            view.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_state_warning));
            newSeed.setSpecie((String) view.getTag());
            String family = seedManager.getFamilyBySpecie(newSeed.getSpecie());
            newSeed.setFamily(family);
            seedWidgetLong.setSeed(newSeed);
            seedWidgetLong.invalidate();
        }
    });

}

From source file:self.philbrown.droidQuery.$.java

/**
 * If the first view of the current selection is a subclass of {@link AdapterView}, this will loop through all the 
 * adapter data and invoke the given function, passing the varargs:
 * <ol>//w  w w .j  a  v  a 2s  . c  om
 * <li>the item from the adapter
 * <li>the index
 * </ol>
 * Otherwise, if the first view in the current selection is a subclass of {@link ViewGroup}, {@code each} will
 * loop through all the child views, and wrap each one in a droidQuery object. The invoked
 * function will receive it, and an int for the index of the selected child view.
 * @param function Function the function to invoke
 * @return this
 */
public $ children(Function function) {
    if (view(0) instanceof AdapterView) {
        AdapterView<?> group = (AdapterView<?>) view(0);
        for (int i = 0; i < (group).getCount(); i++) {
            function.invoke($.this, group.getItemAtPosition(i), i);
        }
    } else if (view(0) instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view(0);
        for (int i = 0; i < group.getChildCount(); i++) {
            function.invoke($.with(group.getChildAt(i)), i);
        }
    }
    return this;
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void setLocalFilelistItemClickListener() {
    if (localFileListView == null)
        return;//w w  w .j a v a  2s . c  o  m
    localFileListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            for (int j = 0; j < parent.getChildCount(); j++)
                parent.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
            FileListItem item = localFileListAdapter.getItem(position);
            if (!isUiEnabled())
                return;
            if (localFileListAdapter.isItemSelected()) {
                item.setChecked(!item.isChecked());
                localFileListAdapter.notifyDataSetChanged();
            } else {
                setUiEnabled(false);
                sendDebugLogMsg(1, "I", "Local filelist item clicked :" + item.getName());
                if (item.isDir()) {
                    FileListCacheItem dhi_c = getFileListCache(item.getPath() + "/" + item.getName(),
                            localFileListCache);
                    ArrayList<FileListItem> tfl = null;
                    if (dhi_c == null) {
                        tfl = createLocalFileList(false, item.getPath() + "/" + item.getName());
                    } else {
                        tfl = dhi_c.file_list;
                    }
                    if (tfl == null)
                        return;
                    String t_dir = item.getPath() + "/" + item.getName();
                    localCurrFLI.pos_fv = localFileListView.getFirstVisiblePosition();
                    if (localFileListView.getChildAt(0) != null)
                        localCurrFLI.pos_top = localFileListView.getChildAt(0).getTop();
                    localDir = t_dir.replace(localBase + "/", "");
                    localFileListAdapter.setDataList(tfl);
                    localFileListAdapter.notifyDataSetChanged();
                    for (int j = 0; j < localFileListView.getChildCount(); j++)
                        localFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                    setFilelistCurrDir(localFileListDirSpinner, localBase, localDir);
                    setFileListPathName(localFileListPathBtn, localFileListCache, localBase, localDir);
                    setEmptyFolderView();
                    localFileListView.setSelection(0);
                    putDirHist(localBase, localDir, localDirHist);

                    if (dhi_c == null) {
                        FileListCacheItem dhi = new FileListCacheItem();
                        dhi.profile_name = localBase;
                        dhi = new FileListCacheItem();
                        dhi = new FileListCacheItem();
                        dhi.base = localBase;
                        dhi.directory = item.getPath() + "/" + item.getName();
                        dhi.file_list = tfl;
                        dhi.directory_history.addAll(localDirHist);
                        putFileListCache(dhi, localFileListCache);
                        localCurrFLI = dhi;
                    } else {
                        localCurrFLI = dhi_c;
                    }
                    localFileListTopBtn.setEnabled(true);
                    localFileListUpBtn.setEnabled(true);
                    setUiEnabled(true);
                } else {
                    if (isFileListItemSelected(localFileListAdapter)) {
                        item.setChecked(!item.isChecked());
                        localFileListAdapter.notifyDataSetChanged();
                        setUiEnabled(true);
                    } else {
                        setUiEnabled(true);
                        startLocalFileViewerIntent(item);
                    }
                }
            }
        }
    });
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void setRemoteFilelistItemClickListener() {
    if (remoteFileListView == null)
        return;/*from  w  w w.ja v a  2s. c om*/
    remoteFileListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            for (int j = 0; j < parent.getChildCount(); j++)
                parent.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
            if (!isUiEnabled())
                return;
            final FileListItem item = remoteFileListAdapter.getItem(position);
            sendDebugLogMsg(1, "I", "Remote filelist item clicked :" + item.getName());
            if (remoteFileListAdapter.isItemSelected()) {
                item.setChecked(!item.isChecked());
                remoteFileListAdapter.notifyDataSetChanged();
            } else {
                setUiEnabled(false);
                if (item.isDir()) {
                    NotifyEvent ne = new NotifyEvent(mContext);
                    ne.setListener(new NotifyEventListener() {
                        @Override
                        public void positiveResponse(Context c, Object[] o) {
                            String t_dir = item.getPath() + "/" + item.getName();

                            remoteCurrFLI.pos_fv = remoteFileListView.getFirstVisiblePosition();
                            if (remoteFileListView.getChildAt(0) != null)
                                remoteCurrFLI.pos_top = remoteFileListView.getChildAt(0).getTop();
                            remoteDir = t_dir.replace(remoteBase + "/", "");

                            remoteFileListAdapter = (FileListAdapter) o[0];
                            remoteFileListView.setAdapter(remoteFileListAdapter);
                            remoteFileListAdapter.notifyDataSetChanged();
                            for (int j = 0; j < remoteFileListView.getChildCount(); j++)
                                remoteFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                            setFilelistCurrDir(remoteFileListDirSpinner, remoteBase, remoteDir);
                            setFileListPathName(remoteFileListPathBtn, remoteFileListCache, remoteBase,
                                    remoteDir);
                            setEmptyFolderView();
                            remoteFileListView.setSelection(0);
                            putDirHist(remoteBase, remoteDir, remoteDirHist);

                            FileListCacheItem dhi = new FileListCacheItem();
                            dhi.profile_name = remoteFileListDirSpinner.getSelectedItem().toString();
                            dhi.base = remoteBase;
                            dhi.directory = t_dir;
                            dhi.file_list = remoteFileListAdapter.getDataList();
                            dhi.directory_history.addAll(remoteDirHist);
                            putFileListCache(dhi, remoteFileListCache);
                            remoteCurrFLI = dhi;

                            setUiEnabled(true);

                            remoteFileListTopBtn.setEnabled(true);
                            remoteFileListUpBtn.setEnabled(true);

                        }

                        @Override
                        public void negativeResponse(Context c, Object[] o) {
                            setUiEnabled(true);
                        }
                    });
                    String t_dir = item.getPath() + "/" + item.getName();
                    FileListCacheItem dhi = getFileListCache(t_dir, remoteFileListCache);
                    if (dhi == null) {
                        createRemoteFileList(item.getPath() + "/" + item.getName(), ne);
                    } else {
                        remoteBase = dhi.base;
                        remoteDir = dhi.directory.replace(dhi.base + "/", "");
                        remoteFileListAdapter.setDataList(dhi.file_list);
                        remoteFileListAdapter.notifyDataSetChanged();
                        setFilelistCurrDir(remoteFileListDirSpinner, remoteBase, remoteDir);
                        setFileListPathName(remoteFileListPathBtn, remoteFileListCache, remoteBase, remoteDir);
                        setEmptyFolderView();
                        remoteFileListView.setSelection(0);

                        putDirHist(remoteBase, remoteDir, remoteDirHist);
                        setUiEnabled(true);
                    }
                } else {
                    setUiEnabled(true);
                    if (isFileListItemSelected(remoteFileListAdapter)) {
                        item.setChecked(!item.isChecked());
                        remoteFileListAdapter.notifyDataSetChanged();
                    } else {
                        //                        view.setBackgroundColor(Color.DKGRAY);
                        startRemoteFileViewerIntent(remoteFileListAdapter, item);
                        //commonDlg.showCommonDialog(false,false,"E","","Remote file was not viewd.",null);
                    }
                }
            }
        }
    });
}