Example usage for android.widget ListView setAdapter

List of usage examples for android.widget ListView setAdapter

Introduction

In this page you can find the example usage for android.widget ListView setAdapter.

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Document

Sets the data behind this ListView.

Usage

From source file:com.cleanwiz.applock.ui.adapter.MainPagerAdapter.java

@SuppressLint("InflateParams")
private View buildLockView() {

    View view = mInflater.inflate(R.layout.pager_applock, null);
    ListView listView = (ListView) view.findViewById(R.id.lv_apps);
    final LockAdapter adapter = new LockAdapter(mContext);

    View header = mInflater.inflate(R.layout.pager_applock_header, null);
    final TextView tvSortAlpha = (TextView) header.findViewById(R.id.sort_alpha);
    final TextView tvSortDefault = (TextView) header.findViewById(R.id.sort_default);

    final int colorRed = mContext.getResources().getColor(R.color.text_red);
    final int colorBlack = mContext.getResources().getColor(R.color.md_black_1);
    View.OnClickListener onSort = new View.OnClickListener() {
        @Override//from   w  w w.  j ava2s.  c  om
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.sort_alpha:
                tvSortAlpha.setTextColor(colorRed);
                tvSortDefault.setTextColor(colorBlack);
                adapter.onSort(LockAdapter.SORT_ALPHA);
                break;
            case R.id.sort_default:
                tvSortAlpha.setTextColor(colorBlack);
                tvSortDefault.setTextColor(colorRed);
                adapter.onSort(LockAdapter.SORT_DEFAULT);
                break;
            }
        }
    };

    tvSortAlpha.setOnClickListener(onSort);
    tvSortDefault.setOnClickListener(onSort);
    listView.addHeaderView(header);
    listView.setAdapter(adapter);
    return view;
}

From source file:com.owncloud.android.ui.adapter.FileListListAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;/*from ww w.ja v  a2  s  .co  m*/
    if (view == null) {
        LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.list_item, null);
    }

    if (mFiles != null && mFiles.size() > position) {
        OCFile file = mFiles.get(position);
        TextView fileName = (TextView) view.findViewById(R.id.Filename);
        String name = file.getFileName();
        if (dataSourceShareFile == null)
            dataSourceShareFile = new DbShareFile(mContext);

        Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
        String[] accountNames = account.name.split("@");

        if (accountNames.length > 2) {
            accountName = accountNames[0] + "@" + accountNames[1];
            url = accountNames[2];
        }
        Map<String, String> fileSharers = dataSourceShareFile.getUsersWhoSharedFilesWithMe(accountName);
        TextView sharer = (TextView) view.findViewById(R.id.sharer);
        ImageView shareButton = (ImageView) view.findViewById(R.id.shareItem);
        fileName.setText(name);
        ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
        fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
        ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
        FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
        if (fileSharers.size() != 0 && (!file.equals("Shared") && file.getRemotePath().contains("Shared"))) {
            if (fileSharers.containsKey(name)) {
                sharer.setText(fileSharers.get(name));
                fileSharers.remove(name);
            } else {
                sharer.setText(" ");
            }
        } else {
            sharer.setText(" ");
        }

        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.downloading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.uploading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (file.isDown()) {
            localStateView.setImageResource(R.drawable.local_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else {
            localStateView.setVisibility(View.INVISIBLE);
        }

        TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
        TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
        shareButton.setOnClickListener(new OnClickListener() {
            String shareStatusDisplay;
            int flagShare = 0;

            @Override
            public void onClick(View v) {
                final Dialog dialog = new Dialog(mContext);
                final OCFile fileToBeShared = (OCFile) getItem(position);
                final ArrayAdapter<String> shareWithFriends;
                final ArrayAdapter<String> shareAdapter;
                final String filePath;
                sharedWith = new ArrayList<String>();
                dataSource = new DbFriends(mContext);
                dataSourceShareFile = new DbShareFile(mContext);
                dialog.setContentView(R.layout.share_file_with);
                dialog.setTitle("Share");
                Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
                String[] accountNames = account.name.split("@");

                if (accountNames.length > 2) {
                    accountName = accountNames[0] + "@" + accountNames[1];
                    url = accountNames[2];
                }

                final AutoCompleteTextView textView = (AutoCompleteTextView) dialog
                        .findViewById(R.id.autocompleteshare);
                Button shareBtn = (Button) dialog.findViewById(R.id.ShareBtn);
                Button doneBtn = (Button) dialog.findViewById(R.id.ShareDoneBtn);
                final ListView listview = (ListView) dialog.findViewById(R.id.alreadySharedWithList);

                textView.setThreshold(2);
                final String itemType;

                filePath = "files" + String.valueOf(fileToBeShared.getRemotePath());
                final String fileName = fileToBeShared.getFileName();
                final String fileRemotePath = fileToBeShared.getRemotePath();
                if (dataSourceShareFile == null)
                    dataSourceShareFile = new DbShareFile(mContext);
                sharedWith = dataSourceShareFile.getUsersWithWhomIhaveSharedFile(fileName, fileRemotePath,
                        accountName, String.valueOf(1));
                shareAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        sharedWith);
                listview.setAdapter(shareAdapter);
                final String itemSource;
                if (fileToBeShared.isDirectory()) {
                    itemType = "folder";
                    int lastSlashInFolderPath = filePath.lastIndexOf('/');
                    itemSource = filePath.substring(0, lastSlashInFolderPath);
                } else {
                    itemType = "file";
                    itemSource = filePath;
                }

                //Permissions disabled with friends app
                ArrayList<String> friendList = dataSource.getFriendList(accountName);
                dataSource.close();
                shareWithFriends = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        friendList);
                textView.setAdapter(shareWithFriends);
                textView.setFocusableInTouchMode(true);
                dialog.show();
                textView.setOnItemClickListener(new OnItemClickListener() {

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

                    }
                });
                final Handler finishedHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        shareAdapter.notifyDataSetChanged();
                        Toast.makeText(mContext, shareStatusDisplay, Toast.LENGTH_SHORT).show();

                    }
                };
                shareBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final String shareWith = textView.getText().toString();

                        if (shareWith.equals("")) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext,
                                    "Please enter the friends name with whom you want to share",
                                    Toast.LENGTH_SHORT).show();
                        } else if (sharedWith.contains(shareWith)) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext, "You have shared the file with that person",
                                    Toast.LENGTH_SHORT).show();
                        } else {

                            textView.setText("");
                            Runnable runnable = new Runnable() {
                                @Override
                                public void run() {
                                    HttpPost post = new HttpPost(
                                            "http://" + url + "/owncloud/androidshare.php");
                                    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

                                    params.add(new BasicNameValuePair("itemType", itemType));
                                    params.add(new BasicNameValuePair("itemSource", itemSource));
                                    params.add(new BasicNameValuePair("shareType", shareType));
                                    params.add(new BasicNameValuePair("shareWith", shareWith));
                                    params.add(new BasicNameValuePair("permission", permissions));
                                    params.add(new BasicNameValuePair("uidOwner", accountName));
                                    HttpEntity entity;
                                    String shareSuccess = "false";
                                    try {
                                        entity = new UrlEncodedFormEntity(params, "utf-8");
                                        HttpClient client = new DefaultHttpClient();
                                        post.setEntity(entity);
                                        HttpResponse response = client.execute(post);

                                        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                                            HttpEntity entityresponse = response.getEntity();
                                            String jsonentity = EntityUtils.toString(entityresponse);
                                            JSONObject obj = new JSONObject(jsonentity);
                                            shareSuccess = obj.getString("SHARE_STATUS");
                                            flagShare = 1;
                                            if (shareSuccess.equals("true")) {
                                                dataSourceShareFile.putNewShares(fileName, fileRemotePath,
                                                        accountName, shareWith);
                                                sharedWith.add(shareWith);
                                                shareStatusDisplay = "File share succeeded";
                                            } else if (shareSuccess.equals("INVALID_FILE")) {
                                                shareStatusDisplay = "File you are trying to share does not exist";
                                            } else if (shareSuccess.equals("INVALID_SHARETYPE")) {
                                                shareStatusDisplay = "File Share type is invalid";
                                            } else {
                                                shareStatusDisplay = "Share did not succeed. Please check your internet connection";
                                            }

                                            finishedHandler.sendEmptyMessage(flagShare);

                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }

                                }
                            };
                            new Thread(runnable).start();

                        }

                        if (flagShare == 1) {
                        }

                    }

                });
                doneBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                        //dataSourceShareFile.close();
                    }
                });
            }

        });
        //dataSourceShareFile.close();
        if (!file.isDirectory()) {
            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            // this if-else is needed even thoe fav icon is visible by default
            // because android reuses views in listview
            if (!file.keepInSync()) {
                view.findViewById(R.id.imageView3).setVisibility(View.GONE);
            } else {
                view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
            }

            ListView parentList = (ListView) parent;
            if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
                checkBoxV.setVisibility(View.GONE);
            } else {
                if (parentList.isItemChecked(position)) {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
                } else {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
                }
                checkBoxV.setVisibility(View.VISIBLE);
            }

        } else {

            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            checkBoxV.setVisibility(View.GONE);
            view.findViewById(R.id.imageView3).setVisibility(View.GONE);
        }
    }

    return view;
}

From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    setCancelable(isCancelable);//from  ww w . j a  v  a 2s . c om
    if (TextUtils.isEmpty(positiveText)) {
        positiveText = "OK";
        Log.d("CHECK", "" + com.commonsdroid.fragmentdialog.R.string.ok);
    }

    if (TextUtils.isEmpty(negativeText)) {
        negativeText = "Cancel";
    }
    switch (type) {
    case DIALOG_TYPE_OK:
        /*show dialog with positive button*/
        return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onPositiveButtonClick(identifier);

                    }
                }).create();
    case DIALOG_TYPE_YES_NO:
        /*show dialog with positive and negative button*/
        return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onPositiveButtonClick(identifier);

                    }
                }).setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onNegativeButtonClick(identifier);

                    }
                }).create();
    case DATE_DIALOG:
        /*show date picker dialog*/
        return new DatePickerDialog(getActivity(), AlertFragmentDialog.this, sYear, sMonth, sDate);
    case TIME_DIALOG:
        /*show time picker dialog*/
        return new TimePickerDialog(getActivity(), AlertFragmentDialog.this, sHour, sMinute, true);
    case SIMPLE_LIST_DIALOG:
        /**
         * show simple list dialog
         */
        return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_item).create();
    case SINGLE_CHOICE_LIST_DIALOG:
        /*show single choice list dialog*/
        return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_singlechoice).create();
    case MULTI_CHOICE_LIST_DIALOG:
        /*show multichoice list dialog*/
        Dialog multipleChoice = new Dialog(getActivity());
        multipleChoice.setContentView(R.layout.list_multichoice);
        multipleChoice.setTitle(title);
        ListView listView = (ListView) multipleChoice.findViewById(R.id.lstMultichoiceList);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // Manage selected items here

                CheckedTextView textView = (CheckedTextView) view;
                if (textView.isChecked()) {

                } else {

                }
                Log.e("CHECK", "clicked pos : " + position + " checked : " + textView.isChecked());
            }
        });

        final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.select_dialog_multichoice, dialogList);

        listView.setAdapter(arraySingleChoiceAdapter);
        multipleChoice.show();
        /*multipleChoice.setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
        multipleChoice.setPositiveButton(R.string.cancel, new OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
              dismiss();      
              sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
           }
        });*/
        /* multipleChoice.setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (alSelectedItem.size() != 0) {
                        sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
                    }
                }
            });*/
        //         multipleChoice.create();

        //         singleChoiceListDialog.setCancelable(false);

        /* multipleChoice.setMultiChoiceItems(items, null,
            new DialogInterface.OnMultiChoiceClickListener() {
             @Override
                public void onClick(DialogInterface dialog, int which,
                        boolean isChecked) {
                    if (isChecked) {
                        alSelectedItem.add(items[which]);
                    } else {
                        alSelectedItem.remove(items[which]);
                    }
                }
            });
           multipleChoice.setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
           multipleChoice.setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (alSelectedItem.size() != 0) {
                        sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
                    }
                }
            });*/
        return multipleChoice;//.create();

    }
    return null;
}

From source file:com.google.example.eightbitartist.DrawingActivity.java

/**
 * Set the list of words to display for guessing.
 *//*from w  w w.  j av  a2 s  .  c om*/
private void resetWords(List<String> words) {
    ListView list = (ListView) findViewById(R.id.listView);

    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);

    for (String st : words) {
        adapter.add(st);
    }

    list.setAdapter(adapter);
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.subredditselect);

    // load personal list from saved prefereces, if null use default and save
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(SubredditSelectActivity.this);
    global = ((GlobalObjects) SubredditSelectActivity.this.getApplicationContext());

    // get subreddit list and set adapter
    subredditList = global.getSubredditManager().getSubredditNames();
    subsAdapter = new MySubredditsAdapter(this, subredditList);
    ListView subListView = (ListView) findViewById(R.id.sublist);
    subListView.setAdapter(subsAdapter);
    subListView.setTextFilterEnabled(true);
    subListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String subreddit = ((TextView) view.findViewById(R.id.subreddit_name)).getText().toString();
            global.getSubredditManager().setFeedSubreddit(mAppWidgetId, subreddit);
            updateFeedAndFinish();//from  www. java  2 s.  c o  m
            //System.out.println(sreddit+" selected");
        }
    });
    subsAdapter.sort(new Comparator<String>() {
        @Override
        public int compare(String s, String t1) {
            return s.compareToIgnoreCase(t1);
        }
    });
    // get multi list and set adapter
    mMultiAdapter = new MyMultisAdapter(this);
    ListView multiListView = (ListView) findViewById(R.id.multilist);
    multiListView.setAdapter(mMultiAdapter);
    multiListView.setTextFilterEnabled(true);
    multiListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == mMultiAdapter.getCount() - 1) {
                LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_multi_add,
                        parent, false);
                final EditText name = (EditText) layout.findViewById(R.id.new_multi_name);
                AlertDialog.Builder builder = new AlertDialog.Builder(SubredditSelectActivity.this);
                builder.setTitle("Create A Multi").setView(layout)
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                            }
                        }).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                if (name.getText().toString().equals("")) {
                                    Toast.makeText(SubredditSelectActivity.this,
                                            "Please enter a name for the multi", Toast.LENGTH_LONG).show();
                                    return;
                                }
                                new SubscriptionEditTask(SubscriptionEditTask.ACTION_MULTI_CREATE)
                                        .execute(name.getText().toString());
                                dialogInterface.dismiss();
                            }
                        }).show();
            } else {
                JSONObject multiObj = mMultiAdapter.getItem(position);
                try {
                    String name = multiObj.getString("display_name");
                    String path = multiObj.getString("path");
                    global.getSubredditManager().setFeed(mAppWidgetId, name, path, true);
                    updateFeedAndFinish();
                } catch (JSONException e) {
                    e.printStackTrace();
                    Toast.makeText(SubredditSelectActivity.this, "Error setting multi.", Toast.LENGTH_LONG)
                            .show();
                }
            }
        }
    });

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
            mAppWidgetId = 0; // Id of 4 zeros indicates its the app view, not a widget, that is being updated
        } else {
            String action = getIntent().getAction();
            widgetFirstTimeSetup = action != null
                    && action.equals("android.appwidget.action.APPWIDGET_CONFIGURE");
        }
    } else {
        mAppWidgetId = 0;
    }

    final ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new SimpleTabsAdapter(new String[] { "My Subreddits", "My Multis" },
            new int[] { R.id.sublist, R.id.multilist }, SubredditSelectActivity.this, null));

    LinearLayout tabsLayout = (LinearLayout) findViewById(R.id.tab_widget);
    tabs = new SimpleTabsWidget(SubredditSelectActivity.this, tabsLayout);
    tabs.setViewPager(pager);

    addButton = (Button) findViewById(R.id.addsrbutton);
    addButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(SubredditSelectActivity.this, ViewAllSubredditsActivity.class);
            startActivityForResult(intent, 1);
        }
    });
    refreshButton = (Button) findViewById(R.id.refreshloginbutton);
    refreshButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            if (global.mRedditData.isLoggedIn()) {
                if (pager.getCurrentItem() == 1) {
                    refreshMultireddits();
                } else {
                    refreshSubreddits();
                }
            } else {
                global.mRedditData.initiateLogin(SubredditSelectActivity.this);
            }
        }
    });
    // sort button
    sortBtn = (Button) findViewById(R.id.sortselect);
    String sortTxt = "Sort:  "
            + mSharedPreferences.getString("sort-" + (mAppWidgetId == 0 ? "app" : mAppWidgetId), "hot");
    sortBtn.setText(sortTxt);
    sortBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            showSortDialog();
        }
    });

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    // set theme colors
    setThemeColors();

    GlobalObjects.doShowWelcomeDialog(SubredditSelectActivity.this);
}

From source file:com.android.projectz.teamrocket.thebusapp.activities.SearchLineActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.setTheme(getResources().getIdentifier(SharedPreferencesUtils.getSelectedTheme(this), "style",
            getPackageName()));/*ww w.jav  a2s . com*/
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_line);

    Toolbar toolbarSearchLine = (Toolbar) findViewById(R.id.toolbarSearchLine);
    setSupportActionBar(toolbarSearchLine);
    getSupportActionBar().setTitle(R.string.title_search_line);
    getSupportActionBar().setSubtitle(R.string.subtitle_search_line);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    ListView listView = (ListView) findViewById(R.id.fullBusList);
    String[] listText = { "Belluno - Santa Giustina - Feltre", "Belluno - Mel - Feltre",
            "Belluno - Vittorio Veneto", "Belluno - Feltre - Trento", "Linea BLU", "Linea CELESTE",
            "Linea LILLA", "Linea GIALLA", "Linea ROSSA", "Linea VERDE" };

    final String[] url = { "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/LINEA13_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/LINEA20_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Extra/Bellunese/LINEA41_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Extra/Feltrino/Linea20-27_Trento_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950B_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950C_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950J_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950L_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950R_I.pdf",
            "http://dolomitibus.it/files/orari/2016-invernale/Urbano/BELLUNO/linea950V_I.pdf" };

    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listText);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            startBrowser(url[position]);
        }
    });

    /**
     * questa editText  fatta per filtrare le linee
     */
    EditText editText = (EditText) findViewById(R.id.inputSearch);
    editText.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) {
            SearchLineActivity.this.adapter.getFilter().filter(s);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

private void showFilterEditDialog() {

    @SuppressLint("InflateParams")
    LinearLayout dialogView = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_filter, null); // passing null okay for dialog

    ThemeManager.Theme theme = global.mThemeManager.getActiveTheme("appthemepref");
    int headerColor = Color.parseColor(theme.getValue("header_color"));
    int headerText = Color.parseColor(theme.getValue("header_text"));
    dialogView.findViewById(R.id.filter_header).setBackgroundColor(headerColor);
    ((TextView) dialogView.findViewById(R.id.filter_headert1)).setTextColor(headerText);
    ((TextView) dialogView.findViewById(R.id.filter_headert2)).setTextColor(headerText);

    ListView subList = (ListView) dialogView.findViewById(R.id.filter_subredditList);
    final SubsListAdapter filterSubsAdapter = new SubsListAdapter(SubredditSelectActivity.this, null);
    subList.setAdapter(filterSubsAdapter);

    AlertDialog.Builder builder = new AlertDialog.Builder(SubredditSelectActivity.this);
    builder.setView(dialogView).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override/*from   w  w w .ja va 2 s  .c  o  m*/
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    }).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
            global.getSubredditManager().setAllFilter(filterSubsAdapter.getSubsList());
            needsFeedUpdate = true; // mark feed for updating
        }
    }).show().getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}

From source file:com.csipsimple.ui.help.Help.java

public View getCustomView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.help, container, false);
    ListView lv = (ListView) v.findViewById(android.R.id.list);
    lv.setOnItemClickListener(this);

    ArrayList<HelpEntry> items = new ArrayList<HelpEntry>();

    // FAQ/*from www .  j  a v  a 2s.co  m*/
    if (!TextUtils.isEmpty(CustomDistribution.getFaqLink())) {
        items.add(new HelpEntry(android.R.drawable.ic_menu_info_details, R.string.faq, FAQ));
    }

    // Issue list 
    if (CustomDistribution.showIssueList()) {
        items.add(new HelpEntry(android.R.drawable.ic_menu_view, R.string.view_existing_issues, OPEN_ISSUES));
    }

    // Log collector
    if (!TextUtils.isEmpty(CustomDistribution.getSupportEmail())) {
        if (isRecording()) {
            items.add(new HelpEntry(android.R.drawable.ic_menu_send, R.string.send_logs, SEND_LOGS));
        } else {
            items.add(new HelpEntry(android.R.drawable.ic_menu_save, R.string.record_logs, START_LOGS));
        }
    }

    items.add(new HelpEntry(android.R.drawable.ic_menu_gallery, R.string.legal_information, LEGALS));

    PackageInfo pinfo = PreferencesProviderWrapper.getCurrentPackageInfos(getActivity());
    if (pinfo != null && pinfo.applicationInfo.icon == R.drawable.ic_launcher_nightly) {
        items.add(new HelpEntry(R.drawable.ic_launcher_nightly, R.string.update_nightly_build, NIGHTLY));
    }

    lv.setAdapter(new HelpArrayAdapter(getActivity(), items));

    TextView tv = (TextView) v.findViewById(android.R.id.text1);
    tv.setText(CollectLogs.getApplicationInfo(getActivity()));

    return v;
}

From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Trips.Trips.java

private void getTrips() {
    final String url = API.tripBehavior + "?all=true";
    try {/*from www . j  av a  2  s  .  c  om*/
        final API.doRequest task = new API.doRequest(new API.doRequest.TaskListener() {
            @Override
            public void postExecute(JSONArray result) throws JSONException {
                result.remove(result.length() - 1);

                final ListView listView = (ListView) view.findViewById(R.id.listView);
                final ArrayList<TripData> tripsArray = new ArrayList<TripData>();
                for (int i = 0; i < result.length(); i++) {
                    final JSONObject data = result.getJSONObject(i);
                    if (data.has("start_time")) {
                        TripData tempTripData = new TripData(data);
                        tripsArray.add(tempTripData);
                    }
                }

                Collections.sort(tripsArray, new Comparator<TripData>() {
                    @Override
                    public int compare(TripData b1, TripData b2) {
                        final long delta = b2.start_time - b1.start_time;
                        if (delta > 0) {
                            return 1;
                        } else if (delta < 0) {
                            return -1;
                        } else {
                            return 0;
                        }
                    }
                });

                final FragmentActivity activity = getActivity();
                if (activity == null) {
                    return;
                }
                final TripsDataAdapter adapter = new TripsDataAdapter(activity.getApplicationContext(),
                        tripsArray);
                listView.setAdapter(adapter);

                final ArrayList<TripData> finalTripArray = tripsArray;
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
                        final Intent tripDetails = new Intent(view.getContext(), TripDetails.class);

                        final Bundle bundle = new Bundle();
                        bundle.putSerializable("tripData", finalTripArray.get(position));
                        tripDetails.putExtras(bundle);

                        startActivity(tripDetails);
                    }
                });

                final ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
                switch (tripsArray.size()) {
                case 0:
                    supportActionBar.setTitle("You have no trips.");
                case 1:
                    supportActionBar.setTitle("You have 1 trip.");
                default:
                    supportActionBar.setTitle("You have " + tripsArray.size() + " trips.");
                }

                Log.i("Trip Data", result.toString());
            }
        });

        task.execute(url, "GET").get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}

From source file:com.concentricsky.android.khanacademy.app.ManageDownloadsActivity.java

private void confirmAndDelete() {
    View contentView = getLayoutInflater().inflate(R.layout.dialog_confirm_delete, null, false);
    ListView list = (ListView) contentView.findViewById(R.id.dialog_confirm_delete_list);

    ArrayList<String> titles = new ArrayList<String>();
    final HashSet<Video> videos = new HashSet<Video>();

    SparseBooleanArray positions = gridView.getCheckedItemPositions();
    int n = positions.size();
    for (int i = 0; i < n; ++i) {
        Cursor c = (Cursor) gridView.getItemAtPosition(positions.keyAt(i));
        Video v = new Video();
        v.setReadable_id(c.getString(c.getColumnIndex("readable_id")));
        v.setYoutube_id(c.getString(c.getColumnIndex("youtube_id")));
        v.setDlm_id(c.getLong(c.getColumnIndex("dlm_id")));
        videos.add(v);//w w w  . j  a va  2s  .  c  o m
        titles.add(c.getString(c.getColumnIndex("title")));
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.dialog_confirm_delete_item);
    adapter.addAll(titles);
    list.setAdapter(adapter);

    new AlertDialog.Builder(this).setView(contentView).setMessage(getString(R.string.msg_delete_videos))
            .setPositiveButton(getString(R.string.button_confirm_delete),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            deleteItems(videos);
                            if (actionMode != null) {
                                actionMode.finish();
                            }
                        }
                    })
            .setNegativeButton(getString(R.string.button_cancel), null).show();
}