Example usage for android.widget LinearLayout findViewById

List of usage examples for android.widget LinearLayout findViewById

Introduction

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

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:net.ddns.mlsoftlaberge.trycorder.contacts.ContactAdminFragment.java

/**
 * Builds a notes LinearLayout based on note information from the Contacts Provider.
 * Each note for the contact gets its own LinearLayout object; for example, if the contact
 * has three notes, then 3 LinearLayouts are generated.
 *
 * @param type  From/*  w  w w.  j a  v  a 2  s .c  o m*/
 *              {@link android.provider.ContactsContract.CommonDataKinds.Email#TYPE}
 * @param label From
 *              {@link android.provider.ContactsContract.CommonDataKinds.Email#LABEL}
 * @param email From
 *              {@link android.provider.ContactsContract.CommonDataKinds.Email#ADDRESS}
 * @return A LinearLayout to add to the contact notes layout,
 * populated with the provided notes.
 */
private LinearLayout buildEmailLayout(final int type, final String label, final String email) {

    // Inflates the address layout
    final LinearLayout emailLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contact_email_item, mEmailLayout, false);

    // Gets handles to the view objects in the layout
    final TextView eheaderTextView = (TextView) emailLayout.findViewById(R.id.contact_email_header);
    final TextView emailTextView = (TextView) emailLayout.findViewById(R.id.contact_email_item);
    final ImageButton editEmailButton = (ImageButton) emailLayout.findViewById(R.id.button_edit_email);

    // If there's no addresses for the contact, shows the empty view and message, and hides the
    // header and button.
    if (email == null) {
        eheaderTextView.setVisibility(View.GONE);
        editEmailButton.setVisibility(View.GONE);
        emailTextView.setText("");
    } else {
        // Gets postal address label type
        CharSequence elabel = android.provider.ContactsContract.CommonDataKinds.Email
                .getTypeLabel(getResources(), type, label);

        // Sets TextView objects in the layout
        eheaderTextView.setText(elabel + " Email");
        emailTextView.setText(email);
        editEmailButton.setContentDescription(email);

        // Defines an onClickListener object for the address button
        editEmailButton.setOnClickListener(new View.OnClickListener() {
            // Defines what to do when users click the address button
            @Override
            public void onClick(View view) {
                buttonsound();
                // Displays a message that no activity can handle the view button.
                Toast.makeText(getActivity(), "Send Email", Toast.LENGTH_SHORT).show();
                emailcontact(view.getContentDescription().toString());
            }
        });

    }
    return emailLayout;
}

From source file:net.ddns.mlsoftlaberge.contactslist.ui.ContactAdminFragment.java

/**
 * Builds an address LinearLayout based on address information from the Contacts Provider.
 * Each address for the contact gets its own LinearLayout object; for example, if the contact
 * has three postal addresses, then 3 LinearLayouts are generated.
 *
 * @param addressType      From/*from ww w . ja v a2 s  . com*/
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#TYPE}
 * @param addressTypeLabel From
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#LABEL}
 * @param address          From
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#FORMATTED_ADDRESS}
 * @return A LinearLayout to add to the contact details layout,
 * populated with the provided address details.
 */
private LinearLayout buildAddressLayout(int addressType, String addressTypeLabel, final String address) {

    // Inflates the address layout
    final LinearLayout addressLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contact_address_item, mAddressLayout, false);

    // Gets handles to the view objects in the layout
    final TextView headerTextView = (TextView) addressLayout.findViewById(R.id.contact_address_header);
    final TextView addressTextView = (TextView) addressLayout.findViewById(R.id.contact_address_full);
    final ImageButton viewAddressButton = (ImageButton) addressLayout.findViewById(R.id.button_view_address);

    // If there's no addresses for the contact, shows the empty view and message, and hides the
    // header and button.
    if (addressTypeLabel == null && addressType == 0) {
        headerTextView.setVisibility(View.GONE);
        viewAddressButton.setVisibility(View.GONE);
        addressTextView.setText(R.string.no_address);
    } else {
        // Gets postal address label type
        CharSequence label = StructuredPostal.getTypeLabel(getResources(), addressType, addressTypeLabel);

        // Sets TextView objects in the layout
        headerTextView.setText(label + " Address");
        addressTextView.setText(address);
        viewAddressButton.setContentDescription(address);

        // Defines an onClickListener object for the address button
        viewAddressButton.setOnClickListener(new View.OnClickListener() {
            // Defines what to do when users click the address button
            @Override
            public void onClick(View view) {

                final Intent viewIntent = new Intent(Intent.ACTION_VIEW,
                        constructGeoUri(view.getContentDescription().toString()));

                // A PackageManager instance is needed to verify that there's a default app
                // that handles ACTION_VIEW and a geo Uri.
                final PackageManager packageManager = getActivity().getPackageManager();

                // Checks for an activity that can handle this intent. Preferred in this
                // case over Intent.createChooser() as it will still let the user choose
                // a default (or use a previously set default) for geo Uris.
                if (packageManager.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    // Toast.makeText(getActivity(),
                    //        R.string.yes_intent_found, Toast.LENGTH_SHORT).show();
                    startActivity(viewIntent);
                } else {
                    // If no default is found, displays a message that no activity can handle
                    // the view button.
                    Toast.makeText(getActivity(), R.string.no_intent_found, Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
    return addressLayout;
}

From source file:eu.focusnet.app.ui.activity.ProjectsListingActivity.java

/**
 * When clicking the action bar buttons:
 * - display an alert dialog that allows to trigger data synchronization or displays the current
 * status of the synchronization.//from   ww  w.ja va2 s  .com
 *
 * @param item Inherited.
 * @return Inherited.
 */
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_sync:

        if (!this.cronBound) {
            return false;
        }

        LayoutInflater inflater = getLayoutInflater();
        // FIXME pass a better Context than null.
        final LinearLayout dialogContent = (LinearLayout) inflater
                .inflate(R.layout.dialog_content_synchronization, null);

        final Context context = this;
        final FocusDialogBuilder builder = new FocusDialogBuilder(context).removeNeutralButton()
                .setNegativeButtonText(getString(R.string.cancel))
                .setPositiveButtonText(getString(R.string.start)).setCancelable(false)
                .insertContent(dialogContent).setTitle(getString(R.string.data_sync_title));
        final AlertDialog dialog = builder.create();
        dialog.show();

        // Cancelation listener
        builder.getNegativeButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                builder.setNegativeButtonText(getString(R.string.sync_continue_background));
                dialog.dismiss();
            }
        });

        final View instructions = dialogContent.findViewById(R.id.dialog_sync_instructions);
        final View progress = dialogContent.findViewById(R.id.dialog_sync_progress);
        final View status = dialogContent.findViewById(R.id.dialog_sync_status);
        final TextView instructionsField = (TextView) instructions
                .findViewById(R.id.dialog_sync_instructions_msg);
        final TextView statusField = (TextView) status.findViewById(R.id.dialog_sync_status_field);

        // update dynamic content (last sync and last data volume)
        String lastSync;
        if (this.cronService.getLastSync() == 0) {
            lastSync = getString(R.string.n_a);
        } else {
            DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance();
            lastSync = dateFormat.format(new Date(this.cronService.getLastSync()));
        }
        TextView lastSyncField = (TextView) instructions.findViewById(R.id.dialog_sync_last_sync_field);
        lastSyncField.setText(getString(R.string.last_sync_label) + lastSync);
        TextView lastDataVolumeField = (TextView) instructions.findViewById(R.id.dialog_sync_data_volume_field);

        long rawDbSize = FocusAppLogic.getDataManager().getDatabaseSize();
        lastDataVolumeField.setText(getString(R.string.last_sync_data_volume_label)
                + (rawDbSize == 0 ? "N/A" : UiHelper.getFileSize(rawDbSize)));

        // too early since last sync
        // display instructions with custom message, disable START
        if (cronService.getLastSync() >= System.currentTimeMillis()
                - Constant.AppConfig.CRON_SERVICE_MINIMUM_DURATION_BETWEEN_SYNC_DATA_IN_MILLISECONDS) {
            instructionsField.setText(R.string.sync_too_recent);
            builder.removePositiveButton();
            builder.setNegativeButtonText(getString(R.string.close));
        }
        // ongoing sync
        // display status and remove START
        else if (this.cronService.getSyncInProgress()) {
            builder.removePositiveButton();
            builder.setNegativeButtonText(getString(R.string.close));

            statusField.setText(R.string.sync_already_in_progress);
            statusField.setTextColor(getResources().getColor(R.color.orange));

            instructions.setVisibility(View.GONE);
            status.setVisibility(View.VISIBLE);
        }
        // Otherwise, set information about last synchronization and data volume and expect the user to start a manual synchronization
        else {
            // create START listener
            builder.getPositiveButton().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    builder.removePositiveButton();
                    builder.setNegativeButtonText(getString(R.string.sync_continue_background));
                    instructions.setVisibility(View.GONE);
                    progress.setVisibility(View.VISIBLE);

                    // Run the periodic task
                    new SyncTask(builder, dialogContent, dialog)
                            .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });
        }
        return true;

    default:
        // If we got here, the user's action was not recognized.
        // Invoke the superclass to handle it.
        // toggle nav drawer on selecting action bar app icon/title
        if (drawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        // Handle action bar actions click
        switch (item.getItemId()) {
        default:
            return super.onOptionsItemSelected(item);
        }
    }
}

From source file:net.ddns.mlsoftlaberge.trycorder.contacts.ContactAdminFragment.java

/**
 * Builds an address LinearLayout based on address information from the Contacts Provider.
 * Each address for the contact gets its own LinearLayout object; for example, if the contact
 * has three postal addresses, then 3 LinearLayouts are generated.
 *
 * @param addressType      From//w w w .  j  a va 2s  . c o m
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#TYPE}
 * @param addressTypeLabel From
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#LABEL}
 * @param address          From
 *                         {@link android.provider.ContactsContract.CommonDataKinds.StructuredPostal#FORMATTED_ADDRESS}
 * @return A LinearLayout to add to the contact details layout,
 * populated with the provided address details.
 */
private LinearLayout buildAddressLayout(int addressType, String addressTypeLabel, final String address) {

    // Inflates the address layout
    final LinearLayout addressLayout = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.contact_address_item, mAddressLayout, false);

    // Gets handles to the view objects in the layout
    final TextView headerTextView = (TextView) addressLayout.findViewById(R.id.contact_address_header);
    final TextView addressTextView = (TextView) addressLayout.findViewById(R.id.contact_address_full);
    final ImageButton viewAddressButton = (ImageButton) addressLayout.findViewById(R.id.button_view_address);

    // If there's no addresses for the contact, shows the empty view and message, and hides the
    // header and button.
    if (addressTypeLabel == null && addressType == 0) {
        headerTextView.setVisibility(View.GONE);
        viewAddressButton.setVisibility(View.GONE);
        addressTextView.setText(R.string.no_address);
    } else {
        // Gets postal address label type
        CharSequence label = StructuredPostal.getTypeLabel(getResources(), addressType, addressTypeLabel);

        // Sets TextView objects in the layout
        headerTextView.setText(label + " Address");
        addressTextView.setText(address);
        viewAddressButton.setContentDescription(address);

        // Defines an onClickListener object for the address button
        viewAddressButton.setOnClickListener(new View.OnClickListener() {
            // Defines what to do when users click the address button
            @Override
            public void onClick(View view) {
                buttonsound();

                final Intent viewIntent = new Intent(Intent.ACTION_VIEW,
                        constructGeoUri(view.getContentDescription().toString()));

                // A PackageManager instance is needed to verify that there's a default app
                // that handles ACTION_VIEW and a geo Uri.
                final PackageManager packageManager = getActivity().getPackageManager();

                // Checks for an activity that can handle this intent. Preferred in this
                // case over Intent.createChooser() as it will still let the user choose
                // a default (or use a previously set default) for geo Uris.
                if (packageManager.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    // Toast.makeText(getActivity(),
                    //        R.string.yes_intent_found, Toast.LENGTH_SHORT).show();
                    startActivity(viewIntent);
                } else {
                    // If no default is found, displays a message that no activity can handle
                    // the view button.
                    Toast.makeText(getActivity(), R.string.no_intent_found, Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
    return addressLayout;
}

From source file:co.taqat.call.CallActivity.java

private void displayConferenceParticipant(int index, final LinphoneCall call) {
    LinearLayout confView = (LinearLayout) inflater.inflate(R.layout.conf_call_control_row, container, false);
    conferenceList.setId(index + 1);/*from   w w w.  j av a2s .c  o m*/
    TextView contact = (TextView) confView.findViewById(R.id.contactNameOrNumber);

    LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(call.getRemoteAddress());
    if (lContact == null) {
        contact.setText(call.getRemoteAddress().getUserName());
    } else {
        contact.setText(lContact.getFullName());
    }

    registerCallDurationTimer(confView, call);

    ImageView quitConference = (ImageView) confView.findViewById(R.id.quitConference);
    quitConference.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            exitConference(call);
        }
    });
    conferenceList.addView(confView);

}

From source file:org.xingjitong.InCallActivity.java

private void displayCall(Resources resources, LinphoneCall call, int index) {
    String sipUri = call.getRemoteAddress().asStringUriOnly();
    LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    // Control Row
    LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call_control_row, container, false);
    setContactPhone(callView, lAddress, sipUri, resources);
    //yyppcallingfun del
    //displayCallStatusIconAndReturnCallPaused(callView, call);
    setRowBackground(callView, index);/*from ww  w.j a v  a2 s.  c o m*/
    registerCallDurationTimer(callView, call);
    callsList.addView(callView);

    // Image Row
    LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false);
    Uri pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress,
            imageView.getContext().getContentResolver());

    final TextView name = (TextView) imageView.findViewById(R.id.call_name);
    //yyppcalling //yyppcallingui add
    //callhint = (TextView) imageView.findViewById(R.id.incall_callhint);

    phone = sipUri.substring(sipUri.indexOf(":") + 1, sipUri.indexOf("@"));
    if (phone.startsWith("01") && !phone.startsWith("010")) {
        phone = phone.substring(1);
    } else if (phone.startsWith("51201")) {
        phone = phone.substring(4);
    } else if (phone.startsWith("512")) {
        phone = phone.substring(3);
    }
    if (!phone.startsWith("1") && !phone.startsWith("0")) {
        phone = "0" + phone;
    }
    handler.post(new Runnable() {

        @Override
        public void run() {
            String n = ContactDB.Instance().getName(phone);
            if (!n.equals(phone) && n != null) {
                name.invalidate();
                name.setText(n);
            }
        }
    });
    displayOrHideContactPicture(imageView, pictureUri, false);
    callsList.addView(imageView);

    callView.setTag(imageView);
    callView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v.getTag() != null) {
                View imageView = (View) v.getTag();
                if (imageView.getVisibility() == View.VISIBLE)
                    imageView.setVisibility(View.GONE);
                else
                    imageView.setVisibility(View.VISIBLE);
                callsList.invalidate();
            }
        }
    });
}

From source file:com.devwang.logcabin.LogCabinMainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent serverIntent = null;//from www  .  ja v  a 2 s . c  o m
    Toast toast = Toast.makeText(LogCabinMainActivity.this, "", Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    switch (item.getItemId()) {
    case R.id.secure_connect_scan:// 
        // Launch the DeviceListActivity to see devices and do scan
        serverIntent = new Intent(this, DeviceListActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
        return true;
    case R.id.insecure_connect_scan:// 
        // Launch the DeviceListActivity to see devices and do scan
        serverIntent = new Intent(this, DeviceListActivity.class);
        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_INSECURE);
        return true;
    case R.id.app_developer:
        toastDisplay(LogCabinMainActivity.this,
                ":   \n\nQQ:1120341494\n:dongleixiaxue314\n :http://www.devwang.com",
                Gravity.CENTER, R.drawable.hutview, Toast.LENGTH_SHORT);
        return true;
    case R.id.app_cmd_what:
    case R.id.app_voice_what:
        toast.setText(
                "\n\n\n\n...");
        toast.show();
        return true;
    case R.id.app_college:
        toast.setText(R.string.str_college);
        toast.show();
        return true;
    case R.id.app_web_url:
        toastDisplay(LogCabinMainActivity.this,
                getString(R.string.http_devwang_sinaapp_com_logcabin_logcabin_web_php), Gravity.CENTER, 0,
                Toast.LENGTH_SHORT);
        return true;
    case R.id.app_update:

        android.app.AlertDialog.Builder dialog = new AlertDialog.Builder(LogCabinMainActivity.this);
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialogview_appupdate, null);
        dialog.setView(layout);
        appUpdateEditText = (EditText) layout.findViewById(R.id.et_appupdate);
        dialog.setPositiveButton(R.string.str_app_update_sure, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String appUpdateEditTextString = appUpdateEditText.getText().toString();
                if ("devwang".equals(appUpdateEditTextString.toString())) {
                    AppUpdate = true;
                    Toast.makeText(getApplicationContext(), R.string.str_app_update_pass_toast,
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
        dialog.show();
        return true;
    }
    return false;
}

From source file:com.saulcintero.moveon.fragments.History.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout fragmentView = (LinearLayout) inflater.inflate(R.layout.history, container, false);

    act = getActivity();/*from   w ww . j a v a  2s  .c  o  m*/
    mContext = act.getApplicationContext();
    res = getResources();

    prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    editor = prefs.edit();

    tracer = LoggerFactory.getLogger(History.class.getSimpleName());

    uiHelper = new UiLifecycleHelper(act, callback);
    uiHelper.onCreate(savedInstanceState);

    hello_text = (TextView) fragmentView.findViewById(R.id.history_hello_item);
    distance_text = (TextView) fragmentView.findViewById(R.id.history_item_one);
    distance_unit_text = (TextView) fragmentView.findViewById(R.id.history_item_nine);
    sessions_text = (TextView) fragmentView.findViewById(R.id.history_item_two);
    time_text = (TextView) fragmentView.findViewById(R.id.history_item_three);
    calories_text = (TextView) fragmentView.findViewById(R.id.history_item_four);
    historyListView = (ListView) fragmentView.findViewById(R.id.list_routes);

    refreshRoutes();

    intentFilter = new IntentFilter("android.intent.action.REFRESH_ROUTES");
    getActivity().registerReceiver(mReceiverRefreshRoutes, intentFilter);

    intentFilter2 = new IntentFilter("android.intent.action.EXPORT_ROUTES");
    getActivity().registerReceiver(mReceiverExportRoutes, intentFilter2);

    intentFilter3 = new IntentFilter("android.intent.action.EXPORT_AND_SHARE_ROUTES");
    getActivity().registerReceiver(mReceiverExportAndShareRoutes, intentFilter3);

    intentFilter4 = new IntentFilter("android.intent.action.EXPORT_INCREMENT_PROGRESS");
    getActivity().registerReceiver(mReceiverIncrementProgress, intentFilter4);

    intentFilter5 = new IntentFilter("android.intent.action.WRITE_MSG_IN_DIALOG");
    getActivity().registerReceiver(mReceiverWriteInProgressDialog, intentFilter5);

    intentFilter6 = new IntentFilter("android.intent.action.FILTER_ROUTES");
    getActivity().registerReceiver(mReceiverFilterRoutes, intentFilter6);

    intentFilter7 = new IntentFilter("android.intent.action.PUBLISH_TO_FB_WALL");
    getActivity().registerReceiver(mReceiverPublishToFbWall, intentFilter7);

    intentFilter8 = new IntentFilter("android.intent.action.SHOW_OSM_MESSAGE");
    getActivity().registerReceiver(mReceiverShowOsmMessage, intentFilter8);

    intentFilter9 = new IntentFilter("android.intent.action.SHARE_SEND_ACTION");
    getActivity().registerReceiver(mReceiverSendAction, intentFilter9);

    intentFilter10 = new IntentFilter("android.intent.action.IMPORT_ROUTES");
    getActivity().registerReceiver(mReceiverImportRoutes, intentFilter10);

    historyListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long duration) {
            int sum = 0;
            for (int p = 0; p < sectionList.size(); p++) {
                if (p <= position) {
                    if (sectionList.get(p) == 1)
                        sum = sum + 1;
                }
            }

            if (!prefs.getBoolean("blocked", false)) {
                if (!MoveOnService.getIsPracticeRunning()) {
                    int lastAct = Integer.parseInt(idList.get(position - sum).toString());

                    editor.putInt("selected_practice", lastAct);
                    editor.commit();

                    Intent intent = new Intent(act, SummaryHolder.class);
                    startActivity(intent);
                } else {
                    UIFunctionUtils.showMessage(mContext, false, getString(R.string.route_in_progress));
                }
            }
        }
    });

    historyListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long duration) {
            if (!prefs.getBoolean("blocked", false)) {
                if (!MoveOnService.getIsPracticeRunning()) {
                    int sum = 0;
                    for (int p = 0; p < sectionList.size(); p++) {
                        if (p <= position) {
                            if (sectionList.get(p) == 1)
                                sum = sum + 1;
                        }
                    }

                    int lastAct = Integer.parseInt(idList.get(position - sum).toString());

                    editor.putInt("selected_practice", lastAct);
                    editor.commit();

                    UIFunctionUtils.createAlertDialog(act, 1, nameList.get(position - sum).toString());
                } else {
                    UIFunctionUtils.showMessage(mContext, false, getString(R.string.end_route_before));
                }
            }
            return true;
        }
    });

    return fragmentView;
}

From source file:reportsas.com.formulapp.Formulario.java

public LinearLayout obtenerLayout(LayoutInflater infla, Pregunta preg) {
    int id;//from   www.  j  a v  a  2 s  .  c  o  m
    int tipo_pregunta = preg.getTipoPregunta();
    LinearLayout pregunta;
    TextView textView;
    TextView textAyuda;
    switch (tipo_pregunta) {
    case 1:
        id = R.layout.pregunta_texto;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloPregunta);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        break;
    case 2:
        id = R.layout.pregunta_multitexto;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.mtxtTritulo);
        textAyuda = (TextView) pregunta.findViewById(R.id.mtxtAyuda);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    case 3:
        id = R.layout.pregunta_seleccion;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloSeleccion);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_seleccion);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        RadioGroup rg = (RadioGroup) pregunta.findViewById(R.id.opcionesUnica);
        ArrayList<OpcionForm> opciones = preg.getOpciones();
        final ArrayList<RadioButton> rb = new ArrayList<RadioButton>();

        for (int i = 0; i < opciones.size(); i++) {
            OpcionForm opcion = opciones.get(i);
            rb.add(new RadioButton(this));
            rg.addView(rb.get(i));
            rb.get(i).setText(opcion.getEtInicial());

        }
        final TextView respt = (TextView) pregunta.findViewById(R.id.respuestaGruop);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int radioButtonID = group.getCheckedRadioButtonId();
                RadioButton radioButton = (RadioButton) group.findViewById(radioButtonID);
                respt.setText(radioButton.getText());
            }
        });

        break;
    case 4:
        id = R.layout.pregunta_multiple;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloMultiple);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        ArrayList<OpcionForm> opciones2 = preg.getOpciones();
        final EditText ediOtros = new EditText(this);
        ArrayList<CheckBox> cb = new ArrayList<CheckBox>();

        for (int i = 0; i < opciones2.size(); i++) {
            OpcionForm opcion = opciones2.get(i);
            cb.add(new CheckBox(this));
            pregunta.addView(cb.get(i));
            cb.get(i).setText(opcion.getEtInicial());
            if (opcion.getEditble().equals("S")) {

                ediOtros.setEnabled(false);
                ediOtros.setId(R.id.edtTexto);
                pregunta.addView(ediOtros);
                cb.get(i).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            ediOtros.setEnabled(true);
                        } else {
                            ediOtros.setText("");
                            ediOtros.setEnabled(false);
                        }
                    }
                });
            }

        }
        TextView spacio = new TextView(this);
        spacio.setText("        ");
        spacio.setVisibility(View.INVISIBLE);
        pregunta.addView(spacio);
        break;
    case 5:
        id = R.layout.pregunta_escala;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloEscala);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_escala);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());

        TextView etInicial = (TextView) pregunta.findViewById(R.id.etInicial);
        TextView etFinal = (TextView) pregunta.findViewById(R.id.etFinal);
        OpcionForm opci = preg.getOpciones().get(0);
        etInicial.setText(opci.getEtInicial());
        etFinal.setText(opci.getEtFinal());
        final TextView respEscala = (TextView) pregunta.findViewById(R.id.seleEscala);
        RatingBar rtBar = (RatingBar) pregunta.findViewById(R.id.escala);
        rtBar.setNumStars(Integer.parseInt(opci.getValores().get(0).getDescripcion()));
        rtBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                respEscala.setText("" + Math.round(rating));
            }
        });

        break;
    case 6:
        id = R.layout.pregunta_lista;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloLista);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_lista);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        ArrayList<OpcionForm> opciones3 = preg.getOpciones();
        //Creamos la lista
        LinkedList<ObjetoSpinner> opcn = new LinkedList<ObjetoSpinner>();
        //La poblamos con los ejemplos
        for (int i = 0; i < opciones3.size(); i++) {
            opcn.add(new ObjetoSpinner(opciones3.get(i).getIdOpcion(), opciones3.get(i).getEtInicial()));
        }

        //Creamos el adaptador*/
        Spinner listad = (Spinner) pregunta.findViewById(R.id.opcionesListado);
        ArrayAdapter<ObjetoSpinner> spinner_adapter = new ArrayAdapter<ObjetoSpinner>(this,
                android.R.layout.simple_spinner_item, opcn);
        //Aadimos el layout para el men y se lo damos al spinner
        spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        listad.setAdapter(spinner_adapter);

        break;
    case 7:
        id = R.layout.pregunta_tabla;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloTabla);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_tabla);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        TableLayout tba = (TableLayout) pregunta.findViewById(R.id.tablaOpciones);
        ArrayList<OpcionForm> opciones4 = preg.getOpciones();
        ArrayList<RadioButton> radiosbotonoes = new ArrayList<RadioButton>();
        for (int i = 0; i < opciones4.size(); i++) {
            TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.row_pregunta_tabla, null);
            RadioGroup tg_valores = (RadioGroup) row.findViewById(R.id.valoresRow);

            final ArrayList<RadioButton> valoOpc = new ArrayList<RadioButton>();
            ArrayList<Valor> valoresT = opciones4.get(i).getValores();
            for (int k = 0; k < valoresT.size(); k++) {
                RadioButton rb_nuevo = new RadioButton(this);
                rb_nuevo.setText(valoresT.get(k).getDescripcion());
                tg_valores.addView(rb_nuevo);
                valoOpc.add(rb_nuevo);
            }

            ((TextView) row.findViewById(R.id.textoRow)).setText(opciones4.get(i).getEtInicial());
            tba.addView(row);
        }
        TextView espacio = new TextView(this);
        espacio.setText("        ");
        pregunta.addView(espacio);
        break;
    case 8:
        id = R.layout.pregunta_fecha;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloFecha);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_fecha);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    case 9:
        id = R.layout.pregunta_hora;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloHora);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_hora);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    default:
        id = R.layout.pregunta_multiple;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloMultiple);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        break;
    }

    return pregunta;
}

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  v a2s .co 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);
}