Example usage for android.widget AdapterView getItemAtPosition

List of usage examples for android.widget AdapterView getItemAtPosition

Introduction

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

Prototype

public Object getItemAtPosition(int position) 

Source Link

Document

Gets the data associated with the specified position in the list.

Usage

From source file:com.landenlabs.all_devtool.IconBaseFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View rootView = inflater.inflate(R.layout.icon_tab, container, false);
    m_context = this.getActivity();

    m_listView = Ui.viewById(rootView, R.id.iconListView);
    m_listView.removeAllViewsInLayout();

    int[] attrs = { android.R.id.background };
    TypedArray ta = m_context.getTheme().obtainStyledAttributes(attrs);
    m_backgroundColor = ta.getColor(0, -1);
    ta.recycle();/*  w  ww.  jav a 2s  .  c  o m*/
    m_alternateColor = Utils.blend(m_backgroundColor, 0x80d0ffe0);

    m_list.clear();
    addToList();
    Collections.sort(m_list, new Comparator<IconInfo>() {
        @Override
        public int compare(IconInfo icon1, IconInfo icon2) {
            return icon1.fieldStr().compareTo(icon2.fieldStr());
        }
    });

    // TODO - remove duplicates.

    final IconArrayAdapter adapter = new IconArrayAdapter(this.getActivity(), R.layout.icon_list_row,
            R.id.iconName, m_list);
    m_listView.setAdapter(adapter);

    m_listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            IconInfo iconInfo = (IconInfo) parent.getItemAtPosition(position);
            showIconDialog(iconInfo);
        }
    });

    return rootView;
}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditExpenseActivity.java

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

    setContentView(R.layout.edit_expense);

    sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.CANADA);
    expenseName = this.getIntent().getExtras().getString("expenseName");
    claimName = this.getIntent().getExtras().getString("claimName");

    date = (EditText) findViewById(R.id.Edit_Expense_Date2);
    expenseNameInput = (EditText) findViewById(R.id.Edit_Expense_Name2);
    expenseCostInput = (EditText) findViewById(R.id.Edit_Expense_Cost2);
    expenseDescriptionInput = (EditText) findViewById(R.id.Edit_Expense_Description2);
    currencySpinner = (Spinner) findViewById(R.id.CurrencySpinner2);
    categorySpinner = (Spinner) findViewById(R.id.CategorySpinner2);
    expenseReceiptView = (ImageView) findViewById(R.id.Edit_Expense_Image2);

    claimList = ClaimListController.getClaimList();
    claim = claimList.getClaim(claimName);
    expenseList = claim.getExpenseList();
    expense = expenseList.getExpense(expenseName);

    // show initial image
    if (expense.getPicture() != null) {
        imgShow = expense.getPicture();// w w  w  .  j  av a  2s. c o  m

        Bitmap bm = BitmapFactory.decodeByteArray(imgShow, 0, imgShow.length);
        sizeNum = imgShow.length;
        size = sizeNum.toString();
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);

        expenseReceiptView.setMinimumHeight(dm.heightPixels);
        expenseReceiptView.setMinimumWidth(dm.widthPixels);
        expenseReceiptView.setImageBitmap(bm);
    }

    expenseReceiptView.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            // Create the Intent for Image Gallery.
            Intent i = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            // Start new activity with the LOAD_IMAGE_RESULTS to handle back the results when image is picked from the Image Gallery.
            startActivityForResult(i, 1);
            return true;
        }
    });

    expenseReceiptView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            loadPhoto((ImageView) v, 100, 100);
        }
    });

    currencySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            expense.setCurr(parent.getItemAtPosition(position).toString());

        }

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

        }

    });

    categorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            expense.setCat(parent.getItemAtPosition(position).toString());
        }

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

        }

    });
    set_on_click();
}

From source file:com.example.amit.tellymoviebuzzz.PopularSeriesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The CursorAdapter will take data from our cursor and populate the ListView.
    mForecastAdapter = new PopularSeriesAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.popularseries_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_popular_series);
    listView.setAdapter(mForecastAdapter);

    // We'll call our MainActivity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from  w w  w  .  j  a  va  2  s .  c  o m
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                // String locationSetting = Utility.getPreferredLocation(getActivity());
                String movieSetting = "upcoming";

                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);

                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));

                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //        .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                //               locationSetting, cursor.getLong(COL_WEATHER_DATE)
                //       ));

                Intent intent = new Intent(getActivity(), DetailActivity.class).setData(
                        MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, "87101"));

                startActivity(intent);
            }
        }
    });
    return rootView;
}

From source file:ir.isilearning.lmsapp.fragment.SignInFragment.java

private boolean mrLoadUserCourses() throws InterruptedException {
    GetUserCoursesWithoutLoginCaller c = new GetUserCoursesWithoutLoginCaller(
            getActivity().getApplicationContext());
    final String tmpUserName = mUserName.getText().toString();
    c.setUserName(tmpUserName);//  ww w .  j  ava  2 s .c  o  m
    userCourseResult = "START";
    c.join();
    c.start();
    while (userCourseResult.equals("START")) {
        try {
            Thread.sleep(15);
        } catch (Exception ignored) {
        }
    }
    List<String> courses = new ArrayList<String>();
    for (gUserCourse t : gUC) {
        courses.add(t.getCoursetitle());
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, courses);
    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // attaching data adapter to spinner
    mSelectCourseSpinner.setAdapter(dataAdapter);
    mSelectCourseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // On selecting a spinner item
            String item = parent.getItemAtPosition(position).toString();
            selectedUserCourse = null;
            for (gUserCourse t : gUC) {
                if (item.equals(t.getCoursetitle())) {
                    selectedUserCourse = t;
                }
            }
            Gson gson = new Gson();
            Player.setCourseTeacherID(selectedUserCourse.getTeacherCourseid());
            PreferencesHelper.writePairToPreferences(getActivity().getApplicationContext(), "TEACHER_ID",
                    String.valueOf(selectedUserCourse.getTeacherCourseid()));
            PreferencesHelper.writePairToPreferences(getActivity().getApplicationContext(),
                    "SelectedUserCourse", gson.toJson(selectedUserCourse));//Save Selected Course to Shared Preferences.
        }

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

        }
    });
    return gUC.length > 0;
}

From source file:com.example.amit.tellymoviebuzzz.FriendsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The CursorAdapter will take data from our cursor and populate the ListView.
    // mForecastAdapter = new FriendsAdapter(getActivity(),frndlist_new);

    View rootView = inflater.inflate(R.layout.friends_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    listView = (ListView) rootView.findViewById(R.id.listview_friends);
    // listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from   w w w  . j av  a  2  s.  c o  m
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                // String locationSetting = Utility.getPreferredLocation(getActivity());
                String movieSetting = "thisyear";
                //Utility.getPreferredMovie(getActivity());

                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //        .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                //               locationSetting, cursor.getLong(COL_WEATHER_DATE)
                //       ));
                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //         .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, cursor.getString(COL_MOVIE_SETTING)));

                Intent intent = new Intent(getActivity(), DetailActivity.class);
                // .setData(cursor.getString(ImdbFragment.COL_TMDBID));
                intent.putExtra("movieid", cursor.getString(ImdbFragment.COL_TMDBID));

                startActivity(intent);
            }
        }
    });
    return rootView;
}

From source file:org.cesar.geofencesdemo.ui.activities.MainActivity.java

@Override
public void onItemClick(final AdapterView<?> adapterView, final View view, final int position, final long id) {
    String str = (String) adapterView.getItemAtPosition(position);
    Address address = GeofenceUtils.getReverseLocationDetails(this, str);
    if (address != null) {
        CommonUtils.hideSoftKeyboard(this, mAutocompleteText);
        updateCamera(address.getLatitude(), address.getLongitude());
    }// w  ww.j  a  va2s  . c  o m
}

From source file:com.example.android.gcncouponalert.app.CouponsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Log.d(LOG_TAG, "onCreateView");
    // The CouponsAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mCouponsAdapter = new CouponsAdapter(getActivity(), null, 0);
    //mCouponsAdapter = new CouponsAdapter(getContext(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mCouponsAdapter);
    // We'll call our MainActivity

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override/*from   w  w w .  j  a v a2  s. c  o m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                ((Callback) getActivity()).onItemSelected(
                        CouponsContract.CouponEntry.buildCouponUri(cursor.getLong(COL_COUPON_ID)));

                /*
                String remote_id = cursor.getString(COL_REMOTE_ID);
                Uri uriUrl = Uri.parse("http://www.grocerycouponnetwork.com/coupons/?").buildUpon().appendQueryParameter("cid", remote_id).build();
                Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
                startActivity(launchBrowser);
                Log.d(LOG_TAG,"Launched: " + uriUrl.toString());
                */
            }
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the com.example.android.gcncouponalert.app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }
    mCouponsAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:org.spinsuite.bchat.view.V_BChat.java

/**
 * Load Drawer/*  w ww  . j  a v a 2 s  .co m*/
 * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com 14/03/2014, 09:23:22
 * @return void
 */
protected void loadDrawer() {
    //   
    m_DLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    //   
    m_DList = (ListView) findViewById(R.id.left_drawer);
    //   
    m_DLayout.setDrawerShadow(Env.getResourceID(this, R.attr.ic_ab_drawer_shadow), GravityCompat.START);

    m_DList.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            m_DLayout.closeDrawers();
            DisplayBChatContactItem item = (DisplayBChatContactItem) adapter.getItemAtPosition(position);
            onItemSelected(item.getRecord_ID(), item.getValue(), TYPE_REQUEST_USER);
        }
    });

    m_DToggle = new ActionBarDrawerToggle(this, m_DLayout, R.string.drawer_open, R.string.drawer_close) {

        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }

        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
        }
    };
    //   
    m_DToggle.syncState();
    //   Set Toggle
    m_DLayout.setDrawerListener(m_DToggle);
    isDrawerLoaded = true;
}

From source file:tv.acfun.video.CommentsActivity.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override//from  ww  w .j a  va 2  s . c  om
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    Object o = parent.getItemAtPosition(position);
    if (o == null || !(o instanceof Comment))
        return false;
    Comment c = (Comment) o;
    ClipboardManager ma = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        ClipData text = ClipData.newHtmlText(c.userName, c.content, c.content);
        ((android.content.ClipboardManager) ma).setPrimaryClip(text);
    } else {
        ma.setText(c.content);
    }
    Toast.makeText(this, "#" + c.count + "?", 0).show();
    return true;
}

From source file:com.example.mihai.inforoute.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);
    mRouteAdapter = new RouteAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override/*from  w  w  w . j a  v a  2s.c  om*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                Intent intent = new Intent(getActivity(), DetailActivity.class)
                        .setData(RouteContract.WeatherEntry.buildWeatherLocationWithDate(arrivalCity,
                                cursor.getLong(COL_WEATHER_DATE)));
                startActivity(intent);
            }
        }
    });
    return rootView;
}