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.example.android.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The ForecastAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ForecastAdapter(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.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    View emptyView = rootView.findViewById(R.id.listview_forecast_empty);
    mListView.setEmptyView(emptyView);/* w w w  .  j  a  v  a 2  s .  co  m*/
    mListView.setAdapter(mForecastAdapter);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        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());
                ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            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 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);
    }
    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.example.android.pets.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the gender of the pet.
 *//*from   w ww .ja v a2  s.com*/
private void setupSpinner() {
    // Create adapter for spinner. The list options are from the String array it will use
    // the spinner will use the default layout
    ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options,
            android.R.layout.simple_spinner_item);

    // Specify dropdown layout style - simple list view with 1 item per line
    genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    // Apply the adapter to the spinner
    mGenderSpinner.setAdapter(genderSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selection = (String) parent.getItemAtPosition(position);
            if (!TextUtils.isEmpty(selection)) {
                if (selection.equals(getString(R.string.gender_male))) {
                    mGender = PetEntry.GENDER_MALE;
                } else if (selection.equals(getString(R.string.gender_female))) {
                    mGender = PetEntry.GENDER_FEMALE;
                } else {
                    mGender = PetEntry.GENDER_UNKNOWN;
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mGender = PetEntry.GENDER_UNKNOWN;
        }
    });
}

From source file:com.esprit.droidcon.corruption.EtatCivileListActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maillist_layout);
    imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    retry = (Button) findViewById(R.id.retry);
    ButterKnife.bind(this);
    mBackground = mImageView;//ww  w. j av a2  s .  c o m
    moveBackground();
    initToolbar();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    connexionlay = (RelativeLayout) findViewById(R.id.connexionlay);

    mang = new ArrayList<>();

    final ListView listView = (ListView) findViewById(R.id.list_view);

    final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {

        connexionlay.setVisibility(View.GONE);
        // notify user you are online
        final ParseQuery<ParseObject> query = ParseQuery.getQuery("Corruption");
        query.whereEqualTo("Type", "Etat Civil");
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> conThus, ParseException e) {
                if (e == null) {
                    //Log.d("score", "Retrieved " + scoreList.size() + " scores");
                    for (int i = conThus.size() - 1; i > 0; i--) {
                        ParseObject dong = conThus.get(i);
                        //System.out.println(dong.getParseFile("ImageFile").toString());
                        if (dong.getParseFile("AudioFile") != null) {
                            mang.add(new Corruption(dong.getString("Title"), dong.getString("Description"),
                                    dong.getString("Date"), dong.getString("Adress"),
                                    dong.getParseFile("Photo1").getUrl(), dong.getParseFile("Photo2").getUrl(),
                                    dong.getParseFile("Photo3").getUrl(),
                                    dong.getParseFile("AudioFile").getUrl(), dong.getDouble("Long"),
                                    dong.getDouble("Lat"), dong.getString("Heure"), dong.getString("Ville"),
                                    dong.getString("UserNom"), dong.getString("UserAdress"),
                                    dong.getString("UserTel"), dong.getString("UserMail"),
                                    dong.getString("Type"), dong.getString("VideoCode"), dong.getString("Etat")

                            ));

                            mGoogleCardsAdapter = new GoogleCardsTravelAdapter(getApplicationContext(), mang);
                            SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                    mGoogleCardsAdapter);
                            swingBottomInAnimationAdapter.setAbsListView(listView);

                            assert swingBottomInAnimationAdapter.getViewAnimator() != null;
                            swingBottomInAnimationAdapter.getViewAnimator()
                                    .setInitialDelayMillis(INITIAL_DELAY_MILLIS);

                            listView.setClipToPadding(false);
                            listView.setDivider(null);
                            Resources r = getResources();
                            int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                                    r.getDisplayMetrics());
                            listView.setDividerHeight(px);
                            listView.setFadingEdgeLength(0);
                            listView.setFitsSystemWindows(true);
                            px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12,
                                    r.getDisplayMetrics());
                            listView.setPadding(px, px, px, px);
                            listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
                            listView.setAdapter(swingBottomInAnimationAdapter);

                            /*   SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                     new SwipeDismissAdapter(mGoogleCardsAdapter, this));
                               swingBottomInAnimationAdapter.setAbsListView(listView);*/
                        } else

                        {
                            mang.add(new Corruption(dong.getString("Title"), dong.getString("Description"),
                                    dong.getString("Date"), dong.getString("Adress"),
                                    dong.getParseFile("Photo1").getUrl(), dong.getParseFile("Photo2").getUrl(),
                                    dong.getParseFile("Photo3").getUrl(), dong.getDouble("Long"),
                                    dong.getDouble("Lat"), dong.getString("Heure"), dong.getString("Ville"),
                                    dong.getString("UserNom"), dong.getString("UserAdress"),
                                    dong.getString("UserTel"), dong.getString("UserMail"),
                                    dong.getString("Type"), dong.getString("VideoCode"), dong.getString("Etat")

                            ));

                            mGoogleCardsAdapter = new GoogleCardsTravelAdapter(getApplicationContext(), mang);
                            SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                    mGoogleCardsAdapter);
                            swingBottomInAnimationAdapter.setAbsListView(listView);

                            assert swingBottomInAnimationAdapter.getViewAnimator() != null;
                            swingBottomInAnimationAdapter.getViewAnimator()
                                    .setInitialDelayMillis(INITIAL_DELAY_MILLIS);

                            listView.setClipToPadding(false);
                            listView.setDivider(null);
                            Resources r = getResources();
                            int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                                    r.getDisplayMetrics());
                            listView.setDividerHeight(px);
                            listView.setFadingEdgeLength(0);
                            listView.setFitsSystemWindows(true);
                            px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12,
                                    r.getDisplayMetrics());
                            listView.setPadding(px, px, px, px);
                            listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
                            listView.setAdapter(swingBottomInAnimationAdapter);

                        }
                    }

                } else {
                    Log.d("score", "Error: " + e.getMessage());
                    Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG)
                            .show();
                }
            }
        });

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

                Corruption corp = (Corruption) parent.getItemAtPosition(position);
                SwipeImageAdapter.img1 = corp.getImage1();
                SwipeImageAdapter.img2 = corp.getImage2();
                SwipeImageAdapter.img3 = corp.getImage3();
                SwipeImageAdapter.title = corp.getTitle();
                SwipeImageAdapter.desc = corp.getDesc();
                //prodimg = prod.getProductImage();
                Intent i = new Intent(EtatCivileListActivity.this, SingleCorruptionActivity.class);
                i.putExtra("audiourl", corp.getAudiofile());
                i.putExtra("longi", corp.getLongi());
                i.putExtra("lat", corp.getLat());
                i.putExtra("title", corp.getTitle());
                i.putExtra("desc", corp.getDesc());
                i.putExtra("date", corp.getDate());
                i.putExtra("heure", corp.getHeure());
                i.putExtra("ville", corp.getVille());
                i.putExtra("usernom", corp.getUserNom());
                i.putExtra("useradress", corp.getUserAdress());
                i.putExtra("usertel", corp.getUserTel());
                i.putExtra("usermail", corp.getUserMail());
                i.putExtra("type", corp.getType());
                i.putExtra("videocode", corp.getVideo());
                i.putExtra("etat", corp.getEtat());

                startActivity(i);
                finish();

            }
        });

    } else {
        // notify user you are not online
        connexionlay.setVisibility(View.VISIBLE);
        retry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // fabProgressCircle.show();
                //  startYourAsynchronousJob();
                Intent refresh = new Intent(EtatCivileListActivity.this, EtatCivileListActivity.class);
                startActivity(refresh);
                finish();

            }
        });

    }

}

From source file:org.catrobat.catroid.content.bricks.BroadcastWaitBrick.java

@Override
public View getView(final Context context, int brickId, BaseAdapter baseAdapter) {
    if (animationState) {
        return view;
    }/*  w  w  w .j  av a2  s  .c  o m*/

    view = View.inflate(context, R.layout.brick_broadcast_wait, null);
    view = getViewWithAlpha(alphaValue);

    setCheckboxView(R.id.brick_broadcast_wait_checkbox);
    final Brick brickInstance = this;

    checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked = isChecked;
            adapter.handleCheck(brickInstance, isChecked);
        }
    });

    final Spinner broadcastSpinner = (Spinner) view.findViewById(R.id.brick_broadcast_wait_spinner);
    broadcastSpinner.setFocusableInTouchMode(false);
    broadcastSpinner.setFocusable(false);
    if (!(checkbox.getVisibility() == View.VISIBLE)) {
        broadcastSpinner.setClickable(true);
        broadcastSpinner.setEnabled(true);
    } else {
        broadcastSpinner.setClickable(false);
        broadcastSpinner.setEnabled(false);
    }

    final ArrayAdapter<String> spinnerAdapter = MessageContainer.getMessageAdapter(context);

    SpinnerAdapterWrapper spinnerAdapterWrapper = new SpinnerAdapterWrapper(context, broadcastSpinner,
            spinnerAdapter);

    broadcastSpinner.setAdapter(spinnerAdapterWrapper);

    broadcastSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        private boolean start = true;

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            if (start) {
                start = false;
                return;
            }
            broadcastMessage = ((String) parent.getItemAtPosition(pos)).trim();
            if (broadcastMessage == context.getString(R.string.new_broadcast_message)) {
                broadcastMessage = "";
            } else {
                oldMessage = broadcastMessage;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    setSpinnerSelection(broadcastSpinner);

    return view;
}

From source file:abanoubm.dayra.main.Main.java

private void sign() {
    String inpath;/*from   w  w w .ja  v a2  s .c  o m*/
    if (android.os.Build.VERSION.SDK_INT >= 17) {
        inpath = getApplicationContext().getApplicationInfo().dataDir + "/databases/";
    } else {
        inpath = "/data/data/" + getApplicationContext().getPackageName() + "/databases/";
    }
    File folder = new File(inpath);
    File[] listOfFiles = folder.listFiles();
    if (listOfFiles == null || listOfFiles.length == 0) {
        Toast.makeText(getApplicationContext(), R.string.msg_no_dayra, Toast.LENGTH_SHORT).show();
    } else {
        ArrayList<String> names = new ArrayList<>(listOfFiles.length);
        for (File file : listOfFiles) {
            if (!file.getName().contains("journal"))
                names.add(file.getName());
        }

        LayoutInflater li = LayoutInflater.from(getApplicationContext());
        View signView = li.inflate(R.layout.dialogue_signin, null, false);
        final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create();
        ad.setView(signView, 0, 0, 0, 0);
        ad.show();

        ListView nameslv = (ListView) signView.findViewById(R.id.databases_lv);
        nameslv.setAdapter(new ArrayAdapter<>(getApplicationContext(), R.layout.item_string, R.id.item, names));

        nameslv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String str = (String) parent.getItemAtPosition(position);
                new SignTask().execute(str);
                ad.dismiss();
            }
        });

    }

}

From source file:net.yolosec.upckeygen.ui.NetworkFragment.java

private void displayResults() {
    if (passwordList.isEmpty()) {
        root.findViewById(R.id.loading_spinner).setVisibility(View.GONE);
        messages.setText(R.string.msg_errnomatches);

    } else {/*from w ww.j  a  va2 s .com*/
        WiFiKey wiFiKey = passwordList.get(0);
        boolean isUbee = TextUtils.isEmpty(wiFiKey.getSerial());

        final ListView list = (ListView) root.findViewById(R.id.list_keys);
        Collections.sort(passwordList, new Comparator<WiFiKey>() {
            @Override
            public int compare(WiFiKey lhs, WiFiKey rhs) {
                if (lhs.getBandType() != rhs.getBandType()) {
                    return lhs.getBandType() < rhs.getBandType() ? -1 : 1;
                }

                final String serialL = lhs.getSerial();
                final String serialR = rhs.getSerial();
                if (serialL == null && serialR != null) {
                    return -1;
                } else if (serialL != null && serialR == null) {
                    return 1;
                } else if (serialL != null && !serialL.equals(serialR)) {
                    return serialL.compareTo(serialR);
                }

                return lhs.getKey().compareTo(rhs.getKey());
            }
        });

        list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final WiFiKey key = (WiFiKey) parent.getItemAtPosition(position);
                Toast.makeText(getActivity(), getString(R.string.msg_copied, key.getKey()), Toast.LENGTH_SHORT)
                        .show();

                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(key.getKey());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("key", key.getKey());
                    clipboard.setPrimaryClip(clip);
                }

                openWifiSettings();
            }
        });
        if (isUbee) {
            list.setAdapter(
                    new WiFiKeyUbeeAdapter(getActivity(), android.R.layout.simple_list_item_1, passwordList));
        } else {
            list.setAdapter(
                    new WiFiKeyAdapter(getActivity(), android.R.layout.simple_list_item_1, passwordList));
        }

        root.showNext();
    }
}

From source file:com.esprit.droidcon.corruption.MusicNewsActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.maillist_layout);
    imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(this));
    retry = (Button) findViewById(R.id.retry);
    ButterKnife.bind(this);
    mBackground = mImageView;//from  www .  j a  v a  2 s  . co m
    moveBackground();
    initToolbar();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    connexionlay = (RelativeLayout) findViewById(R.id.connexionlay);

    mang = new ArrayList<>();

    final ListView listView = (ListView) findViewById(R.id.list_view);

    final ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {

        connexionlay.setVisibility(View.GONE);
        // notify user you are online
        final ParseQuery<ParseObject> query = ParseQuery.getQuery("Corruption");
        query.whereEqualTo("Type", "Bureau d ordre");
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> conThus, ParseException e) {
                if (e == null) {
                    //Log.d("score", "Retrieved " + scoreList.size() + " scores");
                    for (int i = conThus.size() - 1; i > 0; i--) {
                        ParseObject dong = conThus.get(i);
                        //System.out.println(dong.getParseFile("ImageFile").toString());
                        if (dong.getParseFile("AudioFile") != null) {
                            mang.add(new Corruption(dong.getString("Title"), dong.getString("Description"),
                                    dong.getString("Date"), dong.getString("Adress"),
                                    dong.getParseFile("Photo1").getUrl(), dong.getParseFile("Photo2").getUrl(),
                                    dong.getParseFile("Photo3").getUrl(),
                                    dong.getParseFile("AudioFile").getUrl(), dong.getDouble("Long"),
                                    dong.getDouble("Lat"), dong.getString("Heure"), dong.getString("Ville"),
                                    dong.getString("UserNom"), dong.getString("UserAdress"),
                                    dong.getString("UserTel"), dong.getString("UserMail"),
                                    dong.getString("Type"), dong.getString("VideoCode"), dong.getString("Etat")

                            ));

                            mGoogleCardsAdapter = new GoogleCardsTravelAdapter(getApplicationContext(), mang);
                            SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                    mGoogleCardsAdapter);
                            swingBottomInAnimationAdapter.setAbsListView(listView);

                            assert swingBottomInAnimationAdapter.getViewAnimator() != null;
                            swingBottomInAnimationAdapter.getViewAnimator()
                                    .setInitialDelayMillis(INITIAL_DELAY_MILLIS);

                            listView.setClipToPadding(false);
                            listView.setDivider(null);
                            Resources r = getResources();
                            int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                                    r.getDisplayMetrics());
                            listView.setDividerHeight(px);
                            listView.setFadingEdgeLength(0);
                            listView.setFitsSystemWindows(true);
                            px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12,
                                    r.getDisplayMetrics());
                            listView.setPadding(px, px, px, px);
                            listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
                            listView.setAdapter(swingBottomInAnimationAdapter);

                            /*   SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                     new SwipeDismissAdapter(mGoogleCardsAdapter, this));
                               swingBottomInAnimationAdapter.setAbsListView(listView);*/
                        } else

                        {
                            mang.add(new Corruption(dong.getString("Title"), dong.getString("Description"),
                                    dong.getString("Date"), dong.getString("Adress"),
                                    dong.getParseFile("Photo1").getUrl(), dong.getParseFile("Photo2").getUrl(),
                                    dong.getParseFile("Photo3").getUrl(), dong.getDouble("Long"),
                                    dong.getDouble("Lat"), dong.getString("Heure"), dong.getString("Ville"),
                                    dong.getString("UserNom"), dong.getString("UserAdress"),
                                    dong.getString("UserTel"), dong.getString("UserMail"),
                                    dong.getString("Type"), dong.getString("VideoCode"), dong.getString("Etat")

                            ));

                            mGoogleCardsAdapter = new GoogleCardsTravelAdapter(getApplicationContext(), mang);
                            SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
                                    mGoogleCardsAdapter);
                            swingBottomInAnimationAdapter.setAbsListView(listView);

                            assert swingBottomInAnimationAdapter.getViewAnimator() != null;
                            swingBottomInAnimationAdapter.getViewAnimator()
                                    .setInitialDelayMillis(INITIAL_DELAY_MILLIS);

                            listView.setClipToPadding(false);
                            listView.setDivider(null);
                            Resources r = getResources();
                            int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                                    r.getDisplayMetrics());
                            listView.setDividerHeight(px);
                            listView.setFadingEdgeLength(0);
                            listView.setFitsSystemWindows(true);
                            px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12,
                                    r.getDisplayMetrics());
                            listView.setPadding(px, px, px, px);
                            listView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY);
                            listView.setAdapter(swingBottomInAnimationAdapter);

                        }
                    }

                } else {
                    Log.d("score", "Error: " + e.getMessage());
                    Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG)
                            .show();
                }
            }
        });

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

                Corruption corp = (Corruption) parent.getItemAtPosition(position);
                SwipeImageAdapter.img1 = corp.getImage1();
                SwipeImageAdapter.img2 = corp.getImage2();
                SwipeImageAdapter.img3 = corp.getImage3();
                SwipeImageAdapter.title = corp.getTitle();
                SwipeImageAdapter.desc = corp.getDesc();
                //prodimg = prod.getProductImage();
                Intent i = new Intent(MusicNewsActivity.this, SingleCorruptionActivity.class);
                i.putExtra("audiourl", corp.getAudiofile());
                i.putExtra("longi", corp.getLongi());
                i.putExtra("title", corp.getTitle());
                i.putExtra("desc", corp.getDesc());
                i.putExtra("photourl", corp.getImage1());
                i.putExtra("lat", corp.getLat());
                i.putExtra("date", corp.getDate());
                i.putExtra("heure", corp.getHeure());
                i.putExtra("ville", corp.getVille());
                i.putExtra("usernom", corp.getUserNom());
                i.putExtra("useradress", corp.getUserAdress());
                i.putExtra("usertel", corp.getUserTel());
                i.putExtra("usermail", corp.getUserMail());
                i.putExtra("type", corp.getType());
                i.putExtra("videocode", corp.getVideo());
                i.putExtra("etat", corp.getEtat());

                startActivity(i);
                finish();

            }
        });

    } else {
        // notify user you are not online
        connexionlay.setVisibility(View.VISIBLE);
        retry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // fabProgressCircle.show();
                //  startYourAsynchronousJob();
                Intent refresh = new Intent(MusicNewsActivity.this, MusicNewsActivity.class);
                startActivity(refresh);
                finish();

            }
        });

    }

}

From source file:si.vei.pedram.sunshine.fragments.ForecastFragment.java

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

    // The ForecastAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ForecastAdapter(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.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    View emptyView = rootView.findViewById(R.id.listview_forecast_empty);
    mListView.setEmptyView(emptyView);//from   w  w w .  j a va  2  s.co m
    mListView.setAdapter(mForecastAdapter);
    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        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());
                ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            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 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);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.fulltoast.android.sunshine.app.ForecastFragment.java

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

    // The ForecastAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ForecastAdapter(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.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    View emptyView = rootView.findViewById(R.id.listview_forecast_empty);
    mListView.setAdapter(mForecastAdapter);
    mListView.setEmptyView(emptyView);//from  w w  w  . j a v a  2  s  .c  om
    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        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());
                ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            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 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);
    }

    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:fr.forexperts.ui.PortfolioFragment.java

public void showAddDialog() {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View alertView = inflater.inflate(R.layout.alertdialog_add_value, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(alertView);//  w  ww .  ja v  a  2  s. c  o m
    final AlertDialog dialog = builder.create();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
    wmlp.gravity = Gravity.TOP | Gravity.CENTER;
    wmlp.x = 10;
    wmlp.y = 10;

    final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName);
    mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock);
    mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String text = (String) parent.getItemAtPosition(position);
            String[] result = text.split(" ");

            AddTickerTask task = new AddTickerTask();
            task.execute(result[0]);

            dialog.dismiss();
        }
    });

    mStockName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            SuggestStockTask task = new SuggestStockTask();
            task.execute(mStockName.getText().toString());
        }
    });

    // TODO: Change hard coded width
    mStockName.setWidth(10000);

    dialog.show();
}