Example usage for android.widget ListView ListView

List of usage examples for android.widget ListView ListView

Introduction

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

Prototype

public ListView(Context context) 

Source Link

Usage

From source file:org.openremote.android.console.AppSettingsActivity.java

/**
 * It contains a list view to display custom servers, 
 * "Add" button to add custom server, "Delete" button to delete custom server.
 * The custom servers would be saved in customServers.xml. If click a list item, it would be saved as current server.
 * //w w  w .  j  a v  a 2  s  .  c om
 * @return the linear layout
 */
private LinearLayout constructCustomServersView() {
    LinearLayout custumeView = new LinearLayout(this);
    custumeView.setOrientation(LinearLayout.VERTICAL);
    custumeView.setPadding(20, 5, 5, 0);
    custumeView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    ArrayList<String> customServers = new ArrayList<String>();
    initCustomServersFromFile(customServers);

    RelativeLayout buttonsView = new RelativeLayout(this);
    buttonsView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 80));
    Button addServer = new Button(this);
    addServer.setWidth(80);
    RelativeLayout.LayoutParams addServerLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    addServerLayout.addRule(RelativeLayout.CENTER_HORIZONTAL);
    addServer.setLayoutParams(addServerLayout);
    addServer.setText("Add");
    addServer.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(AppSettingsActivity.this, AddServerActivity.class);
            startActivityForResult(intent, Constants.REQUEST_CODE);
        }

    });
    Button deleteServer = new Button(this);
    deleteServer.setWidth(80);
    RelativeLayout.LayoutParams deleteServerLayout = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    deleteServerLayout.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    deleteServer.setLayoutParams(deleteServerLayout);
    deleteServer.setText("Delete");
    deleteServer.setOnClickListener(new OnClickListener() {
        @SuppressWarnings("unchecked")
        public void onClick(View v) {
            int checkedPosition = customListView.getCheckedItemPosition();
            if (!(checkedPosition == ListView.INVALID_POSITION)) {
                customListView.setItemChecked(checkedPosition, false);
                ((ArrayAdapter<String>) customListView.getAdapter())
                        .remove(customListView.getItemAtPosition(checkedPosition).toString());
                currentServer = "";
                AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer);
                writeCustomServerToFile();
            }
        }
    });

    buttonsView.addView(addServer);
    buttonsView.addView(deleteServer);

    customListView = new ListView(this);
    customListView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 200));
    customListView.setCacheColorHint(0);
    final ArrayAdapter<String> serverListAdapter = new ArrayAdapter<String>(appSettingsView.getContext(),
            R.layout.server_list_item, customServers);
    customListView.setAdapter(serverListAdapter);
    customListView.setItemsCanFocus(true);
    customListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    if (currentCustomServerIndex != -1) {
        customListView.setItemChecked(currentCustomServerIndex, true);
        currentServer = (String) customListView.getItemAtPosition(currentCustomServerIndex);
    }
    customListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            currentServer = (String) parent.getItemAtPosition(position);
            AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer);
            writeCustomServerToFile();
            requestPanelList();
            checkAuthentication();
            requestAccess();
        }

    });

    custumeView.addView(customListView);
    custumeView.addView(buttonsView);
    requestPanelList();
    checkAuthentication();
    requestAccess();
    return custumeView;
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.ItemListActivity.java

private void buildUserActionsPopup() {
    ListView listView = new ListView(self);
    listView.setBackgroundColor(Color.WHITE);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override//from w  w  w .j a v a  2 s.  co  m
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            userActionsPopup.dismiss();
        }
    });

    userActionsPopup = new PopupWindow(listView, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    userActionsPopup.setOutsideTouchable(true);
    userActionsPopup.setFocusable(true);
    userActionsPopup.setBackgroundDrawable(new BitmapDrawable());

    View v = userActionsPopup.getContentView();
    v.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                userActionsPopup.dismiss();
            }
            return false;
        }
    });
}

From source file:org.openremote.android.console.AppSettingsActivity.java

/**
 * Auto discovery servers and add them in a list view.
 * Click a list item and make it as current server.
 * //  w ww.  j  a v  a  2s  .co m
 * @return the list view
 */
private ListView constructAutoServersView() {
    final ListView lv = new ListView(this);
    lv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 200));
    lv.setPadding(20, 5, 5, 10);
    lv.setBackgroundColor(0);
    lv.setCacheColorHint(0);
    lv.setItemsCanFocus(true);
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    final ArrayAdapter<String> serverListAdapter = new ArrayAdapter<String>(appSettingsView.getContext(),
            R.layout.server_list_item, new ArrayList<String>());
    lv.setAdapter(serverListAdapter);

    new IPAutoDiscoveryServer() {
        @Override
        protected void onProgressUpdate(Void... values) {
            if (progressLayout != null) {
                progressLayout.setVisibility(View.VISIBLE);
            }
        }

        @Override
        protected void onPostExecute(List<String> result) {
            int length = result.size();
            for (int i = 0; i < length; i++) {
                serverListAdapter.add(result.get(i));
            }
            if (length > 0) {
                lv.setItemChecked(0, true);
                currentServer = serverListAdapter.getItem(0);
                AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer);
            }
            if (progressLayout != null) {
                progressLayout.setVisibility(View.INVISIBLE);
            }
            requestPanelList();
            checkAuthentication();
            requestAccess();
        }
    }.execute((Void) null);

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            currentServer = (String) parent.getItemAtPosition(position);
            AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer);
            requestPanelList();
            checkAuthentication();
            requestAccess();
        }
    });

    return lv;
}

From source file:org.connectbot.ConsoleFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.disconnect: {
        // disconnect or close the currently visible session
        final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip);
        final TerminalBridge bridge = terminalView.bridge;

        bridge.dispatchDisconnect(true);
        return true;
    }/*from  ww w  .  j a  v  a2  s .  c  om*/
    case R.id.copy: {
        // mark as copying and reset any previous bounds
        final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip);
        copySource = terminalView.bridge;

        final SelectionArea area = copySource.getSelectionArea();
        area.reset();
        area.setBounds(copySource.buffer.getColumns(), copySource.buffer.getRows());

        copySource.setSelectingForCopy(true);

        // Make sure we show the initial selection
        copySource.redraw();

        Toast.makeText(getActivity(), getString(R.string.console_copy_start), Toast.LENGTH_LONG).show();
        return true;
    }
    case R.id.paste: {
        // force insert of clipboard text into current console
        final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip);
        final TerminalBridge bridge = terminalView.bridge;

        // pull string from clipboard and generate all events to force down
        final String clip = clipboard.getText().toString();
        bridge.injectString(clip);

        return true;
    }
    case R.id.port_forwards: {
        final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip);
        final TerminalBridge bridge = terminalView.bridge;

        final Intent intent = new Intent(getActivity(), PortForwardListActivity.class);
        intent.putExtra(Intent.EXTRA_TITLE, bridge.host.getId());

        startActivityForResult(intent, REQUEST_EDIT);

        return true;
    }
    case R.id.url_scan: {
        final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip);

        final List<String> urls = terminalView.bridge.scanForURLs();

        final Dialog urlDialog = new Dialog(getActivity());
        urlDialog.setTitle(R.string.console_menu_urlscan);

        ListView urlListView = new ListView(getActivity());

        final URLItemListener urlListener = new URLItemListener(getActivity());
        urlListView.setOnItemClickListener(urlListener);

        urlListView
                .setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, urls));
        urlDialog.setContentView(urlListView);
        urlDialog.show();

        return true;
    }
    case R.id.resize: {
        final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip);

        final View resizeView = inflater.inflate(R.layout.dia_resize, null, false);
        new AlertDialog.Builder(getActivity()).setView(resizeView)
                .setPositiveButton(R.string.button_resize, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        final int width, height;
                        try {
                            width = Integer.parseInt(
                                    ((EditText) resizeView.findViewById(R.id.width)).getText().toString());
                            height = Integer.parseInt(
                                    ((EditText) resizeView.findViewById(R.id.height)).getText().toString());
                        } catch (NumberFormatException nfe) {
                            // TODO change this to a real dialog where we can
                            // make the input boxes turn red to indicate an error.
                            return;
                        }

                        terminalView.forceSize(width, height);
                    }
                }).setNegativeButton(android.R.string.cancel, null).create().show();

        return true;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.sft.blackcatapp.EnrollSchoolActivity.java

private void showOpenCityPopupWindow(View parent) {
    if (openCityPopupWindow == null) {
        LinearLayout popWindowLayout = (LinearLayout) View.inflate(mContext, R.layout.pop_window, null);
        popWindowLayout.removeAllViews();
        // LinearLayout popWindowLayout = new LinearLayout(mContext);
        popWindowLayout.setOrientation(LinearLayout.VERTICAL);
        ListView OpenCityListView = new ListView(mContext);
        OpenCityListView.setDividerHeight(0);
        OpenCityListView.setCacheColorHint(android.R.color.transparent);
        OpenCityListView.setOnItemClickListener(new OnItemClickListener() {

            @Override//from  www  .j a va 2  s  .  c om
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                OpenCityVO selectCity = openCityList.get(position);
                System.out.println(selectCity.getName());
                cityname = selectCity.getName();
                licensetype = "";
                schoolname = "";
                ordertype = "";
                index = 1;
                obtainNearBySchool();
                openCityPopupWindow.dismiss();
                openCityPopupWindow = null;
            }
        });
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        popWindowLayout.addView(OpenCityListView, param);
        OpenCityAdapter openCityAdapter = new OpenCityAdapter(mContext, openCityList);
        OpenCityListView.setAdapter(openCityAdapter);

        openCityPopupWindow = new PopupWindow(popWindowLayout, 130, LayoutParams.WRAP_CONTENT);
    }
    openCityPopupWindow.setFocusable(true);
    openCityPopupWindow.setOutsideTouchable(true);
    // Back???
    openCityPopupWindow.setBackgroundDrawable(new BitmapDrawable());

    openCityPopupWindow.showAsDropDown(parent);
}

From source file:com.undatech.opaque.RemoteCanvasActivity.java

/**
 * Creates the help dialog for this activity.
 *///from   w w w  .  j a  va  2s .c o  m
private Dialog createHelpDialog() {
    AlertDialog.Builder adb = new AlertDialog.Builder(this).setMessage(R.string.input_method_help_text)
            .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // We don't have to do anything.
                }
            });
    Dialog d = adb.setView(new ListView(this)).create();
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    d.show();
    d.getWindow().setAttributes(lp);
    return d;
}

From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java

/**
 * Creates the help dialog for this activity.
 *//*  www . j  a  v  a 2 s . c  o  m*/
private Dialog createHelpDialog() {
    AlertDialog.Builder adb = new AlertDialog.Builder(this).setMessage(R.string.input_mode_help_text)
            .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // We don't have to do anything.
                }
            });
    Dialog d = adb.setView(new ListView(this)).create();
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    d.show();
    d.getWindow().setAttributes(lp);
    return d;
}

From source file:com.df.app.procedures.CarRecogniseLayout.java

/**
 * ?//from  w  ww. jav  a 2s  . c om
 * @param array
 * @param mCallback
 * @throws JSONException
 */
private void showModelChooseDialog(String[] array, final OnChooseModelFinished mCallback) throws JSONException {
    array[array.length - 1] = "";

    View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null);

    final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create();

    TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea);
    final ListView listView = new ListView(view1.getContext());
    listView.setAdapter(
            new ArrayAdapter<String>(view1.getContext(), android.R.layout.simple_list_item_1, array));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            try {
                mCallback.onFinished(i);
                dialog.dismiss();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });

    contentArea.addView(listView);

    setTextView(view1, R.id.title, getResources().getString(R.string.select_model));

    dialog.show();
}

From source file:org.connectbot.ConsoleActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    TerminalView view = adapter.getCurrentTerminalView();
    final boolean activeTerminal = view != null;
    boolean sessionOpen = false;
    boolean disconnected = false;
    boolean canForwardPorts = false;

    if (activeTerminal) {
        TerminalBridge bridge = view.bridge;
        sessionOpen = bridge.isSessionOpen();
        disconnected = bridge.isDisconnected();
        canForwardPorts = bridge.canFowardPorts();
    }//  ww w  . ja va 2 s .  c  o  m

    menu.setQwertyMode(true);

    disconnect = menu.add(R.string.list_host_disconnect);
    if (hardKeyboard)
        disconnect.setAlphabeticShortcut('w');
    if (!sessionOpen && disconnected)
        disconnect.setTitle(R.string.console_menu_close);
    disconnect.setEnabled(activeTerminal);
    disconnect.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    disconnect.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            // disconnect or close the currently visible session
            TerminalView terminalView = adapter.getCurrentTerminalView();
            TerminalBridge bridge = terminalView.bridge;

            bridge.dispatchDisconnect(true);
            return true;
        }
    });

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        copy = menu.add(R.string.console_menu_copy);
        if (hardKeyboard)
            copy.setAlphabeticShortcut('c');
        MenuItemCompat.setShowAsAction(copy, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
        copy.setIcon(R.drawable.ic_action_copy);
        copy.setEnabled(activeTerminal);
        copy.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                adapter.getCurrentTerminalView().startPreHoneycombCopyMode();
                Toast.makeText(ConsoleActivity.this, getString(R.string.console_copy_start), Toast.LENGTH_LONG)
                        .show();
                return true;
            }
        });
    }

    paste = menu.add(R.string.console_menu_paste);
    if (hardKeyboard)
        paste.setAlphabeticShortcut('v');
    MenuItemCompat.setShowAsAction(paste, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    paste.setIcon(R.drawable.ic_action_paste);
    paste.setEnabled(activeTerminal);
    paste.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            pasteIntoTerminal();
            return true;
        }
    });

    portForward = menu.add(R.string.console_menu_portforwards);
    if (hardKeyboard)
        portForward.setAlphabeticShortcut('f');
    portForward.setIcon(android.R.drawable.ic_menu_manage);
    portForward.setEnabled(sessionOpen && canForwardPorts);
    portForward.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            TerminalView terminalView = adapter.getCurrentTerminalView();
            TerminalBridge bridge = terminalView.bridge;

            Intent intent = new Intent(ConsoleActivity.this, PortForwardListActivity.class);
            intent.putExtra(Intent.EXTRA_TITLE, bridge.host.getId());
            ConsoleActivity.this.startActivityForResult(intent, REQUEST_EDIT);
            return true;
        }
    });

    urlscan = menu.add(R.string.console_menu_urlscan);
    if (hardKeyboard)
        urlscan.setAlphabeticShortcut('u');
    urlscan.setIcon(android.R.drawable.ic_menu_search);
    urlscan.setEnabled(activeTerminal);
    urlscan.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            final TerminalView terminalView = adapter.getCurrentTerminalView();

            List<String> urls = terminalView.bridge.scanForURLs();

            Dialog urlDialog = new Dialog(ConsoleActivity.this);
            urlDialog.setTitle(R.string.console_menu_urlscan);

            ListView urlListView = new ListView(ConsoleActivity.this);
            URLItemListener urlListener = new URLItemListener(ConsoleActivity.this);
            urlListView.setOnItemClickListener(urlListener);

            urlListView.setAdapter(
                    new ArrayAdapter<String>(ConsoleActivity.this, android.R.layout.simple_list_item_1, urls));
            urlDialog.setContentView(urlListView);
            urlDialog.show();

            return true;
        }
    });

    resize = menu.add(R.string.console_menu_resize);
    if (hardKeyboard)
        resize.setAlphabeticShortcut('s');
    resize.setIcon(android.R.drawable.ic_menu_crop);
    resize.setEnabled(sessionOpen);
    resize.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            final TerminalView terminalView = adapter.getCurrentTerminalView();

            @SuppressLint("InflateParams") // Dialogs do not have a parent view.
            final View resizeView = inflater.inflate(R.layout.dia_resize, null, false);
            new android.support.v7.app.AlertDialog.Builder(ConsoleActivity.this, R.style.AlertDialogTheme)
                    .setView(resizeView)
                    .setPositiveButton(R.string.button_resize, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            int width, height;
                            try {
                                width = Integer.parseInt(
                                        ((EditText) resizeView.findViewById(R.id.width)).getText().toString());
                                height = Integer.parseInt(
                                        ((EditText) resizeView.findViewById(R.id.height)).getText().toString());
                            } catch (NumberFormatException nfe) {
                                // TODO change this to a real dialog where we can
                                // make the input boxes turn red to indicate an error.
                                return;
                            }

                            terminalView.forceSize(width, height);
                        }
                    }).setNegativeButton(android.R.string.cancel, null).create().show();

            return true;
        }
    });

    return true;
}

From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java

private void setupListView() {
    String[] keys = getResources().getStringArray(R.array.tr_preset_types);
    if (adapter == null) {
        adapter = new ArrayAdapter<String>(this, R.layout.task_rabbit_menu_row, keys);
        menuList = new ListView(this);
        menuList.setAdapter(adapter);//from  w w  w. j  a  va  2  s. c  om
        menuList.setCacheColorHint(Color.TRANSPARENT);

        menuList.setSelection(0);
        menuList.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                currentSelectedItem = position;
                displayViewsForMode(position);
                menuPopover.dismiss();
            }
        });
    } else {
        adapter = new ArrayAdapter<String>(this, R.layout.task_rabbit_menu_row, keys);
        menuList.setAdapter(adapter);
    }
}