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:cn.ucai.wechat.ui.RobotsActivity.java

@Override
@TargetApi(14)//  www . j  a  va2  s . c o  m
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.em_fragment_robots);
    inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    ListView mListView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light, android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
    }
    progressBar = findViewById(R.id.progress_bar);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh() {
            getRobotNamesFromServer();
        }
    });
    Map<String, RobotUser> robotMap = WeChatHelper.getInstance().getRobotList();
    if (robotMap != null) {
        robotList.addAll(robotMap.values());
    } else {
        progressBar.setVisibility(View.VISIBLE);
        getRobotNamesFromServer();
    }
    adapter = new RobotAdapter(this, 1, robotList);
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RobotUser user = (RobotUser) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            intent.setClass(RobotsActivity.this, ChatActivity.class);
            intent.putExtra("userId", user.getUsername());
            startActivity(intent);
        }
    });
    mListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
}

From source file:com.cj.arcard.ui.RobotsActivity.java

@Override
@TargetApi(14)// w  w w  .j ava 2s .c  o  m
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.em_fragment_robots);
    inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    ListView mListView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light, android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
    }
    progressBar = findViewById(R.id.progress_bar);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh() {
            getRobotNamesFromServer();
        }
    });
    Map<String, RobotUser> robotMap = DemoHelper.getInstance().getRobotList();
    if (robotMap != null) {
        robotList.addAll(robotMap.values());
    } else {
        progressBar.setVisibility(View.VISIBLE);
        getRobotNamesFromServer();
    }
    adapter = new RobotAdapter(this, 1, robotList);
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RobotUser user = (RobotUser) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            intent.setClass(RobotsActivity.this, ChatActivity.class);
            intent.putExtra("userId", user.getUsername());
            startActivity(intent);
        }
    });
    mListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
}

From source file:com.efithealth.app.activity.RobotsActivity.java

@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.fragment_robots);
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    mListView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    swipeRefreshLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
            android.R.color.holo_orange_light, android.R.color.holo_red_light);
    progressBar = findViewById(R.id.progress_bar);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override/*from  w ww  . j av a 2  s . c  o  m*/
        public void onRefresh() {
            getRobotNamesFromServer();
        }
    });
    Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
    if (robotMap != null) {
        robotList.addAll(robotMap.values());
    } else {
        progressBar.setVisibility(View.VISIBLE);
        getRobotNamesFromServer();
    }
    adapter = new RobotAdapter(this, 1, robotList);
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RobotUser user = (RobotUser) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            intent.setClass(RobotsActivity.this, ChatActivity.class);
            intent.putExtra("userId", user.getUsername());
            startActivity(intent);
        }
    });
    mListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
}

From source file:com.kevin.cattalk.ui.RobotsActivity.java

@Override
@TargetApi(14)//from  w  ww  .j  a  v a 2  s  . co m
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.em_fragment_robots);
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    ListView mListView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light, android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
    }
    progressBar = findViewById(R.id.progress_bar);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh() {
            getRobotNamesFromServer();
        }
    });
    Map<String, RobotUser> robotMap = DemoHelper.getInstance().getRobotList();
    if (robotMap != null) {
        robotList.addAll(robotMap.values());
    } else {
        progressBar.setVisibility(View.VISIBLE);
        getRobotNamesFromServer();
    }
    adapter = new RobotAdapter(this, 1, robotList);
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RobotUser user = (RobotUser) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            intent.setClass(RobotsActivity.this, ChatActivity.class);
            intent.putExtra("userId", user.getUsername());
            startActivity(intent);
        }
    });
    mListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
}

From source file:it.dex.movingimageview.fragments.MovingTesterFragment.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    String selected = (String) parent.getItemAtPosition(position);
    EVALUATORS evaluatorValue = null;/*from w w w .  j  a v a  2 s. c o m*/
    VALUESGENERATORS generatorValue = null;
    switch (selected) {
    case "Simple":
        evaluatorValue = EVALUATORS.SIMPLE;
        break;
    case "Scroll":
        evaluatorValue = EVALUATORS.SCROLL;
        break;
    case "Time":
        evaluatorValue = EVALUATORS.TIME;
        break;
    case "Gyroscope":
        evaluatorValue = EVALUATORS.GYROSCOPE;
        break;
    case "Base":
        generatorValue = VALUESGENERATORS.BASE;
        break;
    case "Angled":
        generatorValue = VALUESGENERATORS.ANGLED;
        break;
    }
    if (evaluatorValue != null) {
        dexMovingImageView.setEvaluatorType(evaluatorValue);
        speedSeekBar.setEnabled(evaluatorValue == EVALUATORS.TIME);
    }
    if (generatorValue != null)
        dexMovingImageView.setValuesGeneratorType(generatorValue);
}

From source file:cn.ucai.superwechat.ui.RobotsActivity.java

@Override
@TargetApi(14)// w w  w.  j av a  2  s.c o  m
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.em_fragment_robots);
    inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    ListView mListView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    if (android.os.Build.VERSION.SDK_INT >= 14) {
        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light, android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
    }
    progressBar = findViewById(R.id.progress_bar);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh() {
            getRobotNamesFromServer();
        }
    });
    Map<String, RobotUser> robotMap = SuperWeChatDemoHelper.getInstance().getRobotList();
    if (robotMap != null) {
        robotList.addAll(robotMap.values());
    } else {
        progressBar.setVisibility(View.VISIBLE);
        getRobotNamesFromServer();
    }
    adapter = new RobotAdapter(this, 1, robotList);
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RobotUser user = (RobotUser) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            intent.setClass(RobotsActivity.this, ChatActivity.class);
            intent.putExtra("userId", user.getUsername());
            startActivity(intent);
        }
    });
    mListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
}

From source file:com.app.jiaxiaotong.activity.RobotsActivity.java

@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.fragment_robots);
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    mListView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light, android.R.color.holo_orange_light,
            android.R.color.holo_red_light);
    progressBar = findViewById(R.id.progress_bar);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override/*ww w . j  av  a 2 s  .com*/
        public void onRefresh() {
            getRobotNamesFromServer();
        }
    });
    Map<String, RobotUser> robotMap = ((MyHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
    if (robotMap != null) {
        robotList.addAll(robotMap.values());
    } else {
        progressBar.setVisibility(View.VISIBLE);
        getRobotNamesFromServer();
    }
    adapter = new RobotAdapter(this, 1, robotList);
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RobotUser user = (RobotUser) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            intent.setClass(RobotsActivity.this, ChatActivity.class);
            intent.putExtra("userId", user.getUsername());
            startActivity(intent);
        }
    });
    mListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });
}

From source file:com.example.puter.sunshine.app.ForecastFragment.java

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

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

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

    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setAdapter(mForecastAdapter);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from www  . j  a v a2 s.com
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            mPosition = position;
        }
    });

    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {

        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:sms.spam.NewSmsActivity.java

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

    setContentView(R.layout.new_sms_layout);

    final AutoCompleteTextView autocompleteContact = (AutoCompleteTextView) findViewById(
            R.id.autocompleteContact);/*from ww  w  . j a v  a2 s. c  o m*/
    contactsCursorAdapter = new SimpleCursorAdapter(this, R.layout.autocomplete, null,
            new String[] { ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                    ContactsContract.CommonDataKinds.Phone.NUMBER },
            new int[] { R.id.autocompleteText, R.id.autocompleteNumber }, 0);

    final ContactsLoader loader = new ContactsLoader(this);
    getSupportLoaderManager().initLoader(ContactsLoader.CONTACTS, null, loader);
    getSupportLoaderManager().initLoader(ContactsLoader.NUMBERS, null, loader);

    contactsCursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {
        @Override
        public Cursor runQuery(final CharSequence constraint) {
            if (getSupportLoaderManager().hasRunningLoaders()) {
                return null;
            }

            return new CursorWrapper(loader.getCursor(ContactsLoader.NUMBERS)) {
                int pos, count;
                int[] indexes;

                {
                    this.pos = 0;
                    if (!constraint.equals("")) {
                        this.indexes = new int[super.getCount()];
                        this.count = 0;
                        for (int i = 0, j = 0; i < super.getCount(); ++i) {
                            super.moveToPosition(i);
                            if (super.getString(0).contains(constraint)
                                    || super.getString(1).contains(constraint)) {
                                this.indexes[j++] = i;
                                this.count++;
                            }
                        }
                    } else {
                        this.count = super.getCount();
                        this.indexes = new int[this.count];
                        for (int i = 0; i < count; ++i) {
                            this.indexes[i] = i;
                        }
                    }
                }

                @Override
                public boolean move(int offset) {
                    return this.moveToPosition(this.pos + offset);
                }

                @Override
                public boolean moveToNext() {
                    return this.moveToPosition(this.pos + 1);
                }

                @Override
                public boolean moveToPrevious() {
                    return this.moveToPosition(this.pos - 1);
                }

                @Override
                public boolean moveToFirst() {
                    return this.moveToPosition(0);
                }

                @Override
                public boolean moveToLast() {
                    return this.moveToPosition(this.count - 1);
                }

                @Override
                public boolean moveToPosition(int position) {
                    if (position < 0 || position >= count) {
                        return false;
                    }
                    this.pos = indexes[position];
                    return super.moveToPosition(this.pos);
                }

                @Override
                public int getCount() {
                    return this.count;
                }

                @Override
                public int getPosition() {
                    return this.pos;
                }

                @Override
                public void close() {
                }
            };
        }
    });

    autocompleteContact.setAdapter(contactsCursorAdapter);
    autocompleteContact.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int index, long id) {
            Cursor cursor = (Cursor) adapter.getItemAtPosition(index);
            autocompleteContact.setText(cursor.getString(1));
        }
    });
    //        autocompleteContact.setAdapter(new ArrayAdapter<String>
    //        (this, R.layout.autocomplete, new String[] {"alfa", "beta", "gamma"}));
}

From source file:bus_vn.gena.bus_vn.com.bus_vn.tabs.Tab_list_bus_stop.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Context context = getActivity();
    DbOpenHelper dbOpenHelper = new DbOpenHelper(context);
    SQLiteDatabase db;/* w  ww. j  a  v a  2s  .  c om*/
    db = dbOpenHelper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.clear();
    String st;
    st = "";
    st = "SELECT bus_stop_table.Name FROM bus_stop_path_table INNER JOIN bus_stop_table ON  bus_stop_path_table.Bus_stop_id=bus_stop_table.id ";
    st = st + "INNER JOIN bus_path_table ON  bus_stop_path_table.Bus_path_id=bus_path_table.id ";
    st = st + " WHERE bus_stop_path_table.Bus_path_id='" + busPathId + "'";
    st = st + " AND bus_stop_path_table.Type_day_id='" + typeDay + "'";
    Cursor c = db.rawQuery(st, null);

    while (c.moveToNext()) {
        String st2 = "";
        st2 = c.getString(0);
        results.add(st2);
    }
    //  ??
    ListView lvMain = (ListView) getView().findViewById(R.id.listView1);
    lvMain.setDivider(null);//   ? ListView
    //?? ?
    String[] values = results.toArray(new String[results.size()]);

    // custom adapter ? listview
    //? ClickListener ? listview
    lvMain.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        // ?
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //?  ?
            String busStop = (String) parent.getItemAtPosition(position);
            String busStopId = "";
            Context context = getActivity();
            DbOpenHelper dbOpenHelper = new DbOpenHelper(context);
            SQLiteDatabase db;
            db = dbOpenHelper.getWritableDatabase();
            ContentValues cv = new ContentValues();
            cv.clear();

            String st = "";
            st = "SELECT bus_stop_table.id FROM bus_stop_table ";
            st = st + " WHERE bus_stop_table.Name='" + busStop + "'";
            Cursor c = db.rawQuery(st, null);
            while (c.moveToNext()) {
                busStopId = c.getString(0);
            }
            Intent intent = new Intent(getActivity(), List_bus_time.class);
            intent.putExtra("busPathId", busPathId);
            intent.putExtra("busStopId", busStopId);
            intent.putExtra("typeDay", typeDay);
            //?  ? ?  
            startActivity(intent);
            //     
            // overridePendingTransition(R.anim.slide_left_in, R.anim.slide_left_out);**/
        }
    });
    ListviewArrayAdapter adapter = new ListviewArrayAdapter(getActivity(), values, values.length - 1);
    //     listview
    lvMain.setAdapter(adapter);
}