Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

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

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:edu.cscie71.imm.slacker.plugin.Slacker.java

private void openAuthScreen() {
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);//  www.j  a v  a  2s  . com

            LinearLayout mainLayout = new LinearLayout(cordova.getActivity());
            mainLayout.setOrientation(LinearLayout.VERTICAL);

            inAppWebView = new WebView(cordova.getActivity());
            inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT));
            inAppWebView.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new AuthBrowser();
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);

            inAppWebView.loadUrl(authURL + "?client_id=" + slackClientID + "&scope=" + scope);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            mainLayout.addView(inAppWebView);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(mainLayout);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection
    final Activity activity = getActivity();
    switch (item.getItemId()) {
    case R.id.action_sort:
        return true;
    case R.id.menuSortNewest:
        sort = "New";
        refreshComments();/*from  ww w  . j  ava  2s  .c o  m*/
        activity.invalidateOptionsMenu();
        return true;
    case R.id.menuSortTop:
        sort = "Top";
        refreshComments();
        activity.invalidateOptionsMenu();
        return true;
    case R.id.menuSortBest:
        sort = "Best";
        refreshComments();
        activity.invalidateOptionsMenu();
        return true;
    case R.id.action_refresh:
        refreshComments();
        return true;
    case R.id.action_submit:
        final EditText newGalleryTitle = new EditText(activity);
        newGalleryTitle.setHint("Title");
        newGalleryTitle.setSingleLine();
        new AlertDialog.Builder(activity).setTitle("Set Gallery Title/Press OK to remove")
                .setView(newGalleryTitle)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        if (newGalleryTitle.getText() == null)
                            return;
                        HashMap<String, Object> galleryMap = new HashMap<String, Object>();
                        galleryMap.put("terms", "1");
                        galleryMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE,
                                newGalleryTitle.getText().toString());
                        newGalleryString = newGalleryTitle.getText().toString();
                        try {
                            Fetcher fetcher = new Fetcher(singleImageFragment,
                                    "3/gallery/image/" + imageData.getJSONObject().getString("id"), ApiCall.GET,
                                    galleryMap, ((ImgurHoloActivity) getActivity()).getApiCall(), GALLERY);
                            fetcher.execute();
                        } catch (Exception e) {
                            Log.e("Error!", e.toString());
                        }
                    }
                }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing.
                    }
                }).show();

        return true;
    case R.id.action_edit:
        try {
            final EditText newTitle = new EditText(activity);
            newTitle.setSingleLine();
            if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null"))
                newTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE));
            final EditText newBody = new EditText(activity);
            newBody.setHint(R.string.body_hint_description);
            newTitle.setHint(R.string.body_hint_title);
            if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null"))
                newBody.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION));
            LinearLayout linearLayout = new LinearLayout(activity);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            linearLayout.addView(newTitle);
            linearLayout.addView(newBody);
            new AlertDialog.Builder(activity).setTitle(R.string.dialog_edit_title).setView(linearLayout)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            TextView imageTitle = (TextView) imageLayoutView
                                    .findViewById(R.id.single_image_title);
                            TextView imageDescription = (TextView) imageLayoutView
                                    .findViewById(R.id.single_image_description);
                            if (newTitle.getText() != null && !newTitle.getText().toString().equals("")) {
                                imageTitle.setText(newTitle.getText().toString());
                                imageTitle.setVisibility(View.VISIBLE);
                            } else
                                imageTitle.setVisibility(View.GONE);
                            if (newBody.getText() != null && !newBody.getText().toString().equals("")) {
                                imageDescription.setText(newBody.getText().toString());
                                imageDescription.setVisibility(View.VISIBLE);
                            } else
                                imageDescription.setVisibility(View.GONE);
                            HashMap<String, Object> editImageMap = new HashMap<String, Object>();
                            editImageMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newTitle.getText().toString());
                            editImageMap.put(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION,
                                    newBody.getText().toString());
                            try {
                                Fetcher fetcher = new Fetcher(singleImageFragment,
                                        "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.POST,
                                        editImageMap, ((ImgurHoloActivity) getActivity()).getApiCall(),
                                        EDITIMAGE);
                                fetcher.execute();
                            } catch (JSONException e) {
                                Log.e("Error!", e.toString());
                            }
                        }
                    }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            // Do nothing.
                        }
                    }).show();
        } catch (JSONException e) {
            Log.e("Error!", "oops, some image fields missing values" + e.toString());
        }
        return true;
    case R.id.action_download:
        ImageUtils.downloadImage(this, imageData);
        return true;
    case R.id.action_delete:
        new AlertDialog.Builder(activity).setTitle(R.string.dialog_delete_confirmation_title)
                .setMessage(R.string.dialog_delete_confirmation_summary)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            Fetcher fetcher = new Fetcher(singleImageFragment,
                                    "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.DELETE,
                                    null, ((ImgurHoloActivity) getActivity()).getApiCall(), DELETE);
                            fetcher.execute();
                        } catch (JSONException e) {
                            Log.e("Error!", e.toString());
                        }
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing.
                    }
                }).show();
        return true;
    case R.id.action_copy:
        ImageUtils.copyImageURL(this, imageData);
        return true;
    case R.id.action_share:
        ImageUtils.shareImage(this, imageData);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private void saved() {
    ////////S-A-V-E-D///////////
    LinearLayout SavedParent = (LinearLayout) V.findViewById(R.id.group_pinned);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    //If there are no pinned alarms
    if (touchSaveIndex(0) < 1) {
        View Saved = inflater.inflate(R.layout.saved_item, null);
        Saved.setOnClickListener(this);

        ((TextView) Saved.findViewById(R.id.savedLabel)).setText("No Pinned Alarms");
        ((TextView) Saved.findViewById(R.id.savedLabel)).setTextColor(0xDD999999);
        ((CheckBox) Saved.findViewById(R.id.saveCB)).setChecked(true);
        Saved.findViewById(R.id.saveCB).setEnabled(false);

        ((CompoundButton) Saved.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);

        LinearLayout.LayoutParams sparams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        SavedParent.setLayoutParams(sparams);
        SavedParent.addView(Saved);
    } else {// w w w  .  j  av  a  2 s . c o  m
        for (int i = 1; i <= touchSaveIndex(0); i++) {

            //                View Saved = new View(getApplicationContext());
            View Saved = inflater.inflate(R.layout.saved_item, null);
            Saved.setOnClickListener(this);

            SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet",
                    Context.MODE_WORLD_WRITEABLE);
            Location location = new Location("POINT_LOCATION");
            location.setLatitude(0);
            location.setLongitude(0);
            String address = "No Pinned Alarms";
            if (prefs.contains(SAVED_LATITUDE_KEY + i)) {
                location.setLatitude(prefs.getFloat(SAVED_LATITUDE_KEY + i, 0));
            }
            if (prefs.contains(SAVED_LONGITUDE_KEY + i)) {
                location.setLongitude(prefs.getFloat(SAVED_LONGITUDE_KEY + i, 0));
            }
            if (prefs.contains(SAVED_ADDRESS_KEY + i)) {
                address = (prefs.getString(SAVED_ADDRESS_KEY + i, ""));
            }

            CharSequence name;
            if (!address.equals("")) {
                name = address;
                ((TextView) Saved.findViewById(R.id.savedLabel)).setTextColor(0xDDFFFFFF);
                ((CheckBox) Saved.findViewById(R.id.saveCB)).setChecked(true);
                Saved.findViewById(R.id.saveCB).setTag(i);
                ((CompoundButton) Saved.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);
            } else {
                name = "Error";
                ((TextView) Saved.findViewById(R.id.savedLabel)).setTextColor(0xDD999999);
                ((CheckBox) Saved.findViewById(R.id.saveCB)).setChecked(true);
                Saved.findViewById(R.id.saveCB).setEnabled(false);
            }

            ((CompoundButton) Saved.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);
            ((TextView) Saved.findViewById(R.id.savedLabel)).setText(name);
            ((TextView) Saved.findViewById(R.id.savedLabel)).setTextSize(14);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            SavedParent.setLayoutParams(params);
            SavedParent.addView(Saved);

        }
    }
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Get pressed item information
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    // If Rename Tag pressed
    if (item.getTitle().equals(getResources().getString(R.string.rename_context_menu))) {
        // Create new EdiText and configure
        final EditText tagTitle = new EditText(this);
        tagTitle.setSingleLine(true);//w  ww.j a  va 2  s .c om
        tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

        // Set tagTitle maxLength
        int maxLength = 50;
        InputFilter[] array = new InputFilter[1];
        array[0] = new InputFilter.LengthFilter(maxLength);
        tagTitle.setFilters(array);

        // Get tagName text into EditText
        try {
            assert info != null;
            tagTitle.setText(tags.getJSONObject(info.position).getString("tagName"));

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

        final LinearLayout l = new LinearLayout(this);

        l.setOrientation(LinearLayout.VERTICAL);
        l.addView(tagTitle);

        // Show rename dialog
        new AlertDialog.Builder(this).setTitle(R.string.rename_tag_dialog_title).setView(l)
                .setPositiveButton(R.string.rename_tag_dialog_button, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 'Rename' pressed, change tagName and store
                        try {
                            JSONObject newTagName = tags.getJSONObject(info.position);
                            newTagName.put("tagName", tagTitle.getText());

                            tags.put(info.position, newTagName);
                            adapter.notifyDataSetChanged();

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

                        writeToJSON();

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_renamed,
                                Toast.LENGTH_SHORT);
                        toast.show();

                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);
                    }
                }).show();
        tagTitle.requestFocus();
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

        return true;
    }

    // If Delete Tag pressed
    else if (item.getTitle().equals(getResources().getString(R.string.delete_context_menu))) {
        // Construct dialog message
        String dialogMessage = "";

        assert info != null;
        try {
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog1) + " '"
                    + tags.getJSONObject(info.position).getString("tagName") + "'?";

        } catch (JSONException e) {
            e.printStackTrace();
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog2);
        }

        // Show delete dialog
        new AlertDialog.Builder(this).setMessage(dialogMessage)
                .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JSONArray newArray = new JSONArray();

                        // Copy contents to new array, without the deleted item
                        for (int i = 0; i < tags.length(); i++) {
                            if (i != info.position) {
                                try {
                                    newArray.put(tags.get(i));

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

                        // Equal original array to new array
                        tags = newArray;

                        // Write to file
                        try {
                            settings.put("tags", tags);
                            root.put("settings", settings);

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

                        writeToJSON();

                        adapter.adapterData = tags;
                        adapter.notifyDataSetChanged();

                        updateListViewHeight(listView);

                        // If no tags, show 'Press + to add Tags' textView
                        if (tags.length() == 0)
                            noTags.setVisibility(View.VISIBLE);

                        else
                            noTags.setVisibility(View.INVISIBLE);

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_deleted,
                                Toast.LENGTH_SHORT);
                        toast.show();

                    }
                }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Do nothing, close dialog
                    }
                }).show();

        return true;
    }

    return super.onContextItemSelected(item);
}

From source file:com.andreadec.musicplayer.MainActivity.java

private void showItemInfo(PlayableItem item) {
    if (item == null || item.getInformation() == null)
        return;/*from  w  w  w .j  a  v a 2s  . c  o m*/
    ArrayList<Information> information = item.getInformation();

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.songInfo);
    View view = getLayoutInflater().inflate(R.layout.layout_songinfo, null, false);
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutInformation);

    Bitmap image = item.getImage();
    if (image != null) {
        ImageView imageView = new ImageView(this);
        imageView.setImageBitmap(image);
        linearLayout.addView(imageView);
    }

    for (Information info : information) {
        TextView info1 = new TextView(this);
        info1.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        info1.setText(getResources().getString(info.key));
        TextView info2 = new TextView(this);
        info2.setText(info.value);
        info2.setPadding(0, 0, 0, 10);
        linearLayout.addView(info1);
        linearLayout.addView(info2);
    }

    builder.setView(view);
    builder.setPositiveButton(R.string.ok, null);
    builder.show();
}

From source file:com.launcher.silverfish.TabFragmentHandler.java

/**
 * Loads all tabs from the database./*from www . ja  v  a  2 s .co m*/
 */
public void loadTabs() {
    arrButton = new ArrayList<Button>();
    arrTabs = new ArrayList<TabInfo>();

    LinearLayout tabWidget = (LinearLayout) rootView.findViewById(R.id.custom_tabwidget);

    LauncherSQLiteHelper sql = new LauncherSQLiteHelper(mActivity.getApplicationContext());
    List<TabTable> tabTables = sql.getAllTabs();

    for (TabTable tabEntry : tabTables) {
        TabInfo tab = new TabInfo(tabEntry);
        arrTabs.add(tab);

        // Create a button for each tab
        Button btn = new Button(mActivity.getApplicationContext());
        btn.setText(tab.getLabel());
        arrButton.add(btn);

        // Set the style of the button
        btn.setBackgroundResource(R.drawable.tab_style);
        btn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, 1));
        btn.setTextColor(Color.WHITE);

        // Add the button to the tab widget.
        tabWidget.addView(btn);

        // And create a new tab
        TabHost.TabSpec tSpecFragmentId = tHost.newTabSpec(tab.getTag());
        tSpecFragmentId.setIndicator(tab.getLabel());
        tSpecFragmentId.setContent(new DummyTabContent(mActivity.getBaseContext()));
        tHost.addTab(tSpecFragmentId);
    }

}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

private void initDetails(Cursor data) {
    mIsStarred = (data.getInt(PostDetailsQuery.IS_STARRED) == 1);
    mGeoLat = data.getDouble(PostDetailsQuery.LAT);
    mGeoLng = data.getDouble(PostDetailsQuery.LNG);

    // Start the reverse geocode address search
    if (ConnectionHelper.hasConnection(getActivity())) {
        mView.findViewById(R.id.details_progress_address).setVisibility(View.VISIBLE);
        final Thread thread = new Thread(this);
        thread.start();/* w  ww. j a  va2 s.  c  o m*/
    } else {
        mView.findViewById(R.id.details_progress_address).setVisibility(View.GONE);
    }

    final boolean isForbidden = (data.getInt(PostDetailsQuery.IS_FORBIDDEN) == 1);

    final LinearLayout panelsWrapper = (LinearLayout) mView.findViewById(R.id.details_panels_wrapper);
    panelsWrapper.removeAllViews();

    // Panels LayoutParams and Color
    final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    final float SCALE = getActivity().getResources().getDisplayMetrics().density;
    // Convert dips to pixels
    float valueDips = 16.0f;
    int valuePixels = (int) (valueDips * SCALE);

    params.setMargins(0, 0, 0, valuePixels);

    final int textColor = getResources().getColor(R.color.details_panel_text);
    do {
        final String desc = data.getString(PostDetailsQuery.DESCRIPTION);
        mShareDesc += Const.LINE_SEPARATOR + desc;

        panelsWrapper.addView(getPanel(desc, params, textColor));
    } while (data.moveToNext());

    final TextView titleUi = (TextView) mView.findViewById(R.id.details_title);

    if (isForbidden) {
        titleUi.setText(R.string.details_title_forbidden);
    } else {
        titleUi.setText(R.string.details_title_allowed);
    }

    getSherlockActivity().invalidateOptionsMenu();
}

From source file:com.wallerlab.compcellscope.Image_Gallery.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image__gallery);
    counter = 0;/*from  www.  j  a  va2 s. com*/
    final ImageView currPic = new ImageView(this);

    DisplayMetrics metrics = this.getResources().getDisplayMetrics();
    final int screen_width = metrics.widthPixels;

    SharedPreferences settings = getSharedPreferences(Folder_Chooser.PREFS_NAME, 0);
    //SharedPreferences.Editor edit = settings.edit();
    String path = settings.getString(Folder_Chooser.location_name,
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString());

    //Log.d(LOG, "  |  " + path + " |  ");
    TextView text1 = (TextView) findViewById(R.id.text1);
    final TextView text2 = (TextView) findViewById(R.id.text2);

    text1.setText(path);

    File directory = new File(path);

    // get all the files from a directory
    File[] dump_files = directory.listFiles();
    Log.d(LOG, dump_files.length + " ");

    final File[] fList = removeElements(dump_files, "info.json");

    Log.d(LOG, "Filtered Length: " + fList.length);

    Arrays.sort(fList, new Comparator<File>() {
        @Override
        public int compare(File file, File file2) {
            String one = file.toString();
            String two = file2.toString();
            //Log.d(LOG, "one: " + one);
            //Log.d(LOG, "two: " + two);
            int num_one = Integer.parseInt(one.substring(one.lastIndexOf("(") + 1, one.lastIndexOf(")")));
            int num_two = Integer.parseInt(two.substring(two.lastIndexOf("(") + 1, two.lastIndexOf(")")));
            return num_one - num_two;
        }
    });

    try {
        writeJsonFile(fList);
    } catch (JSONException e) {
        Log.d(LOG, "JSON WRITE FAILED");
    }
    //List names programattically
    LinearLayout myLinearLayout = (LinearLayout) findViewById(R.id.linear_table);
    final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, screen_width + 4);

    myLinearLayout.setOrientation(LinearLayout.VERTICAL);

    if (fList != null) {
        File cur_pic = fList[0];

        BitmapFactory.Options opts = new BitmapFactory.Options();
        Log.d(LOG, "\n File Location: " + cur_pic.getAbsolutePath() + " \n" + " Parent: "
                + cur_pic.getParent().toString() + "\n");

        Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);

        currPic.setLayoutParams(params);
        currPic.setImageBitmap(myImage);
        currPic.setId(View.generateViewId());
        text2.setText(cur_pic.getName());
    }

    myLinearLayout.addView(currPic);

    //Seekbar
    seekBar = (SeekBar) findViewById(R.id.seekBar);
    seekBar.setEnabled(true);
    seekBar.setMax(fList.length - 1);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int progress = 0;
        int length = fList.length;

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            setCounter(i);
            if (getCounter() <= fList.length) {
                File cur_pic = fList[getCounter()];
                BitmapFactory.Options opts = new BitmapFactory.Options();
                opts.inJustDecodeBounds = true;
                Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                int image_width = opts.outWidth;
                int image_height = opts.outHeight;
                int sampleSize = image_width / screen_width;
                opts.inSampleSize = sampleSize;

                text2.setText(cur_pic.getName());

                opts.inJustDecodeBounds = false;
                myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);

                currPic.setImageBitmap(myImage);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    //Make Button Layout
    LinearLayout buttonLayout = new LinearLayout(this);
    buttonLayout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams LLParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
    buttonLayout.setLayoutParams(LLParams);
    buttonLayout.setId(View.generateViewId());

    //Button Layout Params
    LinearLayout.LayoutParams param_button = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);

    //Prev Pic
    Button prevPic = new Button(this);
    prevPic.setText("Previous");
    prevPic.setId(View.generateViewId());
    prevPic.setLayoutParams(param_button);

    prevPic.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (fList != null) {
                decrementCounter();
                if (getCounter() >= 0) {
                    File cur_pic = fList[getCounter()];
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    opts.inJustDecodeBounds = true;
                    Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                    int image_width = opts.outWidth;
                    int image_height = opts.outHeight;
                    int sampleSize = image_width / screen_width;
                    opts.inSampleSize = sampleSize;

                    text2.setText(cur_pic.getName());

                    opts.inJustDecodeBounds = false;
                    myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                    //Log.d(LOG, getCounter() + "");
                    seekBar.setProgress(getCounter());
                    currPic.setImageBitmap(myImage);

                } else {
                    setCounter(0);
                }

            } else {
                Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT);
                setCounter(getCounter() - 1);
            }
        }
    });

    buttonLayout.addView(prevPic);

    // Next Picture  Button
    Button nextPic = new Button(this);
    nextPic.setText("Next");
    nextPic.setId(View.generateViewId());
    nextPic.setLayoutParams(param_button);

    buttonLayout.addView(nextPic);
    nextPic.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (fList != null) {
                incrementCounter();
                if (getCounter() < fList.length) {
                    File cur_pic = fList[getCounter()];
                    BitmapFactory.Options opts = new BitmapFactory.Options();
                    opts.inJustDecodeBounds = true;
                    Bitmap myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                    int image_width = opts.outWidth;
                    int image_height = opts.outHeight;
                    int sampleSize = image_width / screen_width;
                    opts.inSampleSize = sampleSize;

                    text2.setText(cur_pic.getName());

                    opts.inJustDecodeBounds = false;
                    myImage = BitmapFactory.decodeFile(cur_pic.getAbsolutePath(), opts);
                    //Log.d(LOG, getCounter() + "");
                    seekBar.setProgress(getCounter());

                    currPic.setImageBitmap(myImage);
                } else {
                    setCounter(getCounter() - 1);
                }

            } else {
                Toast.makeText(Image_Gallery.this, "There are no pictures in this folder", Toast.LENGTH_SHORT);
                setCounter(getCounter() - 1);
            }
        }
    });

    myLinearLayout.addView(buttonLayout);
}

From source file:de.da_sense.moses.client.FormFragment.java

/**
 * Displays a multiple choice question to the user.
 * @param question the question to be displayed
 * @param linearLayoutInsideAScrollView the view to add the question to
 * @param ordinal the ordinal number of the question i.e. 1, 2, 3, 4 or 5
 *///from  w ww  .  j  a  v  a 2  s  .  c  o m
private void makeMultipleChoice(final Question question, LinearLayout linearLayoutInsideAScrollView,
        int ordinal) {
    LinearLayout questionContainer = generateQuestionContainer(linearLayoutInsideAScrollView);
    String questionText = question.getTitle();
    List<PossibleAnswer> possibleAnswers = question.getPossibleAnswers();
    Collections.sort(possibleAnswers);

    TextView questionView = new TextView(getActivity());
    questionView.setText(ordinal + ". " + questionText);
    if (question.isMandatory())
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyleMandatory);
    else
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyle);
    questionContainer.addView(questionView);
    mQuestionTitleMappings.put(question, questionView);

    Log.i(LOG_TAG, "questionView = " + questionView.getText());

    final HashSet<String> madeAnswers = new HashSet<String>();
    madeAnswers.addAll(Arrays.asList(question.getAnswer().split(",")));
    madeAnswers.remove(""); // paranoia

    final CheckBox[] checkBoxs = new CheckBox[possibleAnswers.size()];
    for (int i = 0; i < checkBoxs.length; i++) {
        final PossibleAnswer possibleAnswer = possibleAnswers.get(i);
        final String possibleAnswerId = String.valueOf(possibleAnswer.getId());
        checkBoxs[i] = new CheckBox(getActivity());
        if (i % 2 == 0)
            checkBoxs[i].setBackgroundColor(getActivity().getResources().getColor(R.color.light_gray));
        checkBoxs[i].setText(possibleAnswer.getTitle());
        checkBoxs[i].setTextAppearance(getActivity(), R.style.PossibleAnswerTextStyle);
        if (madeAnswers.contains(possibleAnswerId))
            checkBoxs[i].setChecked(true);

        // click handling
        checkBoxs[i].setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                    madeAnswers.add(possibleAnswerId);
                else
                    madeAnswers.remove(possibleAnswerId);
                String newAnswer = "";
                for (String madeAnswer1 : madeAnswers)
                    newAnswer = newAnswer + "," + madeAnswer1;
                if (!newAnswer.isEmpty())
                    newAnswer = newAnswer.substring(1); // remove the leading ","
                question.setAnswer(newAnswer);
            }
        });

        checkBoxs[i].setVisibility(View.VISIBLE);
        if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY)
            checkBoxs[i].setEnabled(false);
        questionContainer.addView(checkBoxs[i]);
    }
}