logo
down
shadow

android spinner size automatically changed?


android spinner size automatically changed?

By : Adezj
Date : November 18 2020, 03:49 PM
will be helpful for those in need before adapter set. , Specify the layout_width as 0dp for both spinners.
code :


Share : facebook icon twitter icon
Modify the Size of an Android Spinner Drop down part Size?

Modify the Size of an Android Spinner Drop down part Size?


By : Jack Liu
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can not change the size of spinner as it is default widget. But you can make it custom using background image. Here is my code:
code :
<Spinner 
    android:id="@+id/spinner"
    android:layout_width="fill_parent" 
    android:layout_height="45dp"
    android:drawSelectorOnTop = "true"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="5dp"
    android:layout_marginRight="20dp"
    android:layout_below="@+id/placeCity"
    android:paddingLeft="5dip"
    android:background="@drawable/myspinner_background"
/>
 <ImageView
       android:id="@+id/imageView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignRight="@+id/spinner"
       android:layout_alignTop="@+id/spinner"
       android:layout_marginRight="5dp"
        android:layout_marginTop="10dp"
       android:src="@drawable/down" />
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
    android:color="#f269be"
    android:width="2dp" />
<solid
    android:color="#ECC8EC" />
Automatically Populating a Spinner Based On Previous Spinner - android

Automatically Populating a Spinner Based On Previous Spinner - android


By : Sandeep Rotti
Date : March 29 2020, 07:55 AM
I hope this helps you . you need to move if(parent.getId() == R.id.model_spinner) outside if(parent.getId() == R.id.maufacture_spinner then makesure and call spinnerModel.setOnItemSelectedListener(this) onCreate, to do that you need to move spinnerModel = (Spinner) findViewById(R.id.model_spinner) into your on create, I'd recommend doing the same for all your views, that way you don't call findViewById every time you select a spinner item.
EDIT:
code :
Spinner spinnerManufacture, spinnerModel, spinnerColor;
private ArrayAdapter<String> modelAdapter;
private ArrayAdapter<String> maufactureAdapter;
private ArrayAdapter<String> colorAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    spinnerManufacture = (Spinner) findViewById(R.id.manufacture_spinner);
    spinnerModel = (Spinner) findViewById(R.id.model_spinner);
    spinnerColor = (Spinner) findViewById(R.id.color_spinner);

    maufactureAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, Manufacture);
    modelAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    colorAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);

    maufactureAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    modelAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    colorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spinnerColor.setAdapter(colorAdapter);
    spinnerManufacture.setAdapter(maufactureAdapter);
    spinnerModel.setAdapter(modelAdapter);

    spinnerManufacture.setOnItemSelectedListener(this);
    spinnerModel.setOnItemSelectedListener(this);
    spinnerColor.setOnItemSelectedListener(this);

}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    if (parent.getId() == R.id.maufacture_spinner) {
        String[] model;
        if (spinnerManufacture.getSelectedItem().toString().equals("BMW")){
            model = BMW_Model;
        } else {
            model = new String[] {"not sure what model list to use"};
        }
        modelAdapter.clear();
        modelAdapter.addAll(model);
    }
    if (parent.getId() == R.id.model_spinner) {
        String[] Color;
        if (spinnerModel.getSelectedItem().toString().equals("M3 Coupe")) {
            Color = M3_Color;
        } else if (spinnerModel.getSelectedItem().toString().equals("M5 Sedan")) {
            Color = M5_Color;
        } else {
            Color = new String[] { "not sure what color list to use" };
        }
        colorAdapter.clear();
        colorAdapter.addAll(Color);
    }
}
On configuration changed layout not changed automatically in android

On configuration changed layout not changed automatically in android


By : Sam Mc'Ochieng
Date : March 29 2020, 07:55 AM
wish of those help If you choose to use android:configChanges="orientation|screenSize" then you have manually update the layouts when the screen rotates.
code :
@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);

    if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
    {
        setContentView(R.layout.portrait);
    }
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
        setContentView(R.layout.landscape);
    }
}
public class DetailsFragment extends Fragment
{
    private EditText ed;

    public static DetailsFragment newInstance(int index)
    {
        return new DetailsFragment();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.fragment_layout, container, false);
        ed = (EditText) view.findViewById(R.id.fragment_edit);

        if(null != savedInstanceState)
        {
            //restore the text if null != savedInstanceState -> fragment is recreated
            ed.setText(savedInstanceState.getString("RESTORE_TEXT"));
        }

        return view;
    }

    @Override
    public void onSaveInstanceState(Bundle outState)
    {
        if(null != ed)
        {
            //save the text written in the edittext
            outState.putString("RESTORE_TEXT", ed.getText().toString());
        }

        super.onSaveInstanceState(outState);
    }
}
Why spinner size is changed after loading data and text color?

Why spinner size is changed after loading data and text color?


By : Varun Khanna
Date : March 29 2020, 07:55 AM
Does that help When I load data to the spinner from web service using Retrofit, It increase the height of the spinner and change text color. What is the problem? How can I fix it? , To change spinner size: use padding to 0dp
code :
 <Spinner
    android:id="@+id/spinnerSubZone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="@android:drawable/btn_dropdown"
    android:minHeight="50dp"
    android:padding="0dp"  //add this
    android:textColor="@android:color/holo_blue_bright" />
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.RED); //change color
            ((TextView) parent.getChildAt(0)).setTextSize(10);  //change size
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
Creating dynamic spinners and getting value of every spinner, Whenever a spinner item changed, get all spinner values

Creating dynamic spinners and getting value of every spinner, Whenever a spinner item changed, get all spinner values


By : Vinícius Araújo
Date : March 29 2020, 07:55 AM
I wish did fix the issue. First, you need to set same instance of OnItemSelectListener to your all spinners. Let your activity or fragment implement OnItemSelectListener then call spinner.setOnItemSelectListener(this);
In onItemSelected method you can run this code to have selecteds.
code :
    ArrayList<String> selectedList = new ArrayList();

    for (int i = 0; i < dynamicProductProperties.getChildCount(); i++) {
        View view = dynamicProductProperties.getChildAt(i);
        if (view instanceof Spinner){
           String selected = (String) ((Spinner) view).getSelectedItem();
            selectedList.add(TextUtils.isEmpty(selected) ? "" : selected);
        }
    }
Related Posts Related Posts :
  • Android Studio gradle build failed for hello world app
  • Slide a layout up from bottom of screen
  • Play HTML5 video in iOS/Android native media player
  • How to rescale a bitmap file in android?
  • No view found for id 0x for fragment after rotation?
  • Define different themable styles to the same widget types
  • ProGuard not working in my app
  • FragmentTransaction from BaseAdapter
  • Connecting multiple devices in a Wifi Direct group
  • Why TabActivity is deprecated in android
  • How to capture low resolution picture using android camera
  • android preferenceactivity padding in landscape orientation
  • How can I store cookie in webview?
  • Passing variables from one activity to another
  • Create Multicolored Pie Chart in Android Studio
  • how to kill progress dialog in android
  • Show Error on the tip of the Edit Text Android
  • How do I use getWindowManager() by another java file
  • fetching images from gallery on android phones with internal storage
  • How to discover devices like Google TV and Nexus-Q using MediaRoute API on Android?
  • "Unfortunately your app stopped working"- Facebook Integration for Android
  • How to animate button in android?
  • Resource Not Found Exception in class without context or activity
  • Launching Android Netflix App And Passing Video Id
  • Making a Phone Call with a Number Extension
  • NullPointerException at BoringLayout.isBoring is anything but boring
  • java.lang.RuntimeException: Unable to get provider
  • Testing custom Views with Robolectric
  • tools:listheader doesn't work although tools:listitem does
  • oppo, vivo app kill notification not coming in android fcm
  • OnClick Method could not function correctly with if else statement
  • Best method to download image from url in Android
  • How can I open Drawer Layout moving all the view and not just slide over?
  • how to show profile pictures of friends in a list view?
  • Creating TimePickerDialog with custom style in Android
  • Android 2.3.6 support library v7 option menu is missing
  • need of vblank in Display subssytem
  • Android MP4 stream - Video cannot be played
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org