Example usage for android.widget AdapterView getChildAt

List of usage examples for android.widget AdapterView getChildAt

Introduction

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

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position 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:com.czy.reecycleviewheader.ScrollableHelper.java

private static boolean isAdapterViewTop(AdapterView adapterView) {
    if (adapterView != null) {
        int firstVisiblePosition = adapterView.getFirstVisiblePosition();
        View childAt = adapterView.getChildAt(0);
        if (childAt == null || (firstVisiblePosition == 0 && childAt != null && childAt.getTop() == 0)) {
            return true;
        }/* ww  w. java2s  . co m*/
    }
    return false;
}

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 w  w w .j av a2  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);/*  ww  w  .  j  ava2s .  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:sysnetlab.android.sdc.ui.fragments.ExperimentDataStoreFragment.java

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

    ListView listView = (ListView) mView.findViewById(R.id.listview_experiment_datastore_selecting);

    DataStoreListAdapter storeAdapter = new DataStoreListAdapter(getActivity(),
            ExperimentManagerSingleton.getInstance().getStores(), mItemChecked);

    listView.setAdapter(storeAdapter);//from   www .j  a  v  a 2 s.c om

    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mItemChecked == position) {
                setItemSelected(view, true);
            } else {
                if (mItemChecked >= 0) {
                    setItemSelected(parent.getChildAt(mItemChecked), false);
                }
                setItemSelected(view, true);
                mItemChecked = position;
            }
        }

    });
}

From source file:org.eyeseetea.malariacare.fragments.PlannedFragment.java

private void prepareUI() {
    this.adapter = new PlannedAdapter(plannedItems, getActivity());
    this.setListAdapter(adapter);

    Spinner programSpinner = (Spinner) getActivity().findViewById(R.id.dashboard_planning_program);
    //Populate Program View DDL
    programList.add(0, programDefaultOption);
    programSpinner.setAdapter(new FilterProgramArrayAdapter(getActivity(), programList));
    //Apply filter to listview
    programSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*w  ww  .j  ava  2  s .  co  m*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Spinner spinner = ((Spinner) parent);
            Program selectedProgram = position == 0 ? null : (Program) spinner.getItemAtPosition(position);
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            adapter.applyFilter(selectedProgram);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

}

From source file:wassilni.pl.navigationdrawersi.ui.Search.java

private void showDate() {
    final myList list = new myList(this, searchResults);

    listView.setAdapter(list);/*from w w w . ja v  a  2  s  . c om*/
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            // query and parseJSON, then go to mapActivity.

            arg0.getChildAt(position).setBackgroundColor(getResources().getColor(R.color.gray_shadow));

            arg0.getChildAt(position).setBackgroundColor(getResources().getColor(R.color.transparent));
            list.setBackground();
            schedule s = searchResults.get(position).getSchedule();
            Driver d = searchResults.get(position).getDriver();

            System.out.println("befor " + d.getCar().getYearOfManufacture());
            Intent i = new Intent(Search.this, DriverProfile.class);
            i.putExtra("DriverName", d.getFName() + " " + d.getLName());//json will be parsed in the map activity.
            i.putExtra("DriverPhone", d.getPhone());
            i.putExtra("DriverAge", d.getAge());
            i.putExtra("DriverNationality", d.getNationality());
            i.putExtra("DriverCompany", d.getCompany());
            i.putExtra("carType", d.getCar().getType());
            i.putExtra("carModel", d.getCar().getModel());
            i.putExtra("carCompany", d.getCar().getCompany());
            i.putExtra("carColor", d.getCar().getColor());
            i.putExtra("carYearOfManufacture", d.getCar().getYearOfManufacture() + "");
            i.putExtra("carCapacity", d.getCar().getCapacity() + "");
            i.putExtra("DayPrice", s.dayPrice + "");
            i.putExtra("MonthPrice", s.montPrice + "");
            i.putExtra("Female", d.getFemaleCompanion() + "");
            i.putExtra("tripTime", s.getTime());
            i.putExtra("D_ID", d.getID() + "");
            i.putExtra("S_ID", s.getS_ID() + "");
            i.putExtra("Plate", d.getCar().getPlate());

            startActivity(i);
            //this.finish();

        }
    });

}

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

private void initEvents() {
    this.mTineUnit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/*from  w w  w. j  a v a  2  s.  c  om*/
        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

/**
 * ??/* ww w .  j  a v  a2  s .co  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:com.recyclerviewpulldownrefresh.view.refresh.AbPullToRefreshView.java

/**
 * ??//from  w w  w . ja v a2s .co m
 *
 * @return
 */
public boolean canChildScrollUp() {
    // ???
    if (!mEnablePullRefresh) {
        return false;
    }

    if (mTarget instanceof AdapterView<?>) {
        final AdapterView<?> absListView = (AdapterView<?>) mTarget;
        View child = absListView.getChildAt(0);
        if (child == null) {
            return true;
        }
        if (absListView.getFirstVisiblePosition() == 0 && child.getTop() == 0) {
            return true;
        }

        int top = child.getTop();
        int padding = absListView.getPaddingTop();
        if (absListView.getFirstVisiblePosition() == 0 && Math.abs(top - padding) <= 11) {
            return true;
        }
        return false;
    } else if (mTarget instanceof ScrollView) {
        return mScrollView.getScrollY() == 0;
    } else if (mTarget instanceof WebView) {
        WebView webView = (WebView) mTarget;
        if (webView != null) {
            return webView.getScrollY() == 0;
        }
        return false;
    } else if (mTarget instanceof RecyclerView) {
        int firstVisiblePosition = 0;

        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
        View childView = layoutManager.getChildAt(0);
        if (null == childView) {
            return true;
        }

        if (layoutManager instanceof LinearLayoutManager) {
            firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
        } else if (layoutManager instanceof GridLayoutManager) {
            firstVisiblePosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            int[] spanPosition = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
            ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(spanPosition);
            firstVisiblePosition = getFirstVisibleItemPosition(spanPosition);
        }

        if (childView.getTop() == 0 && firstVisiblePosition == 0) {
            return true;
        }
        return false;
    } else {
        return ViewCompat.canScrollVertically(mTarget, 1);
    }
}