Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to cast text with Spinner in xml file
    primarykey
    data
    text
    <p>I'm to new to android and I'm trying to develop an UI ,but it is giving me the following error,where I'm developing UI that contains text beside to that spinner...</p> <blockquote> <p>java.lang.ClassCastException: android.widget.Spinner cannot be cast to android.widget.TextView</p> </blockquote> <p>and my setting.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;TextView android:id="@+id/minute" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/mile" android:layout_below="@+id/time" android:text="@string/min" /&gt; &lt;TextView android:id="@+id/distance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/time" android:layout_marginTop="34dp" android:text="@string/Distance" /&gt; &lt;TextView android:id="@+id/mile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/notification" android:layout_below="@+id/distance" android:text="@string/mile" android:textAppearance="?android:attr/textAppearanceSmall" /&gt; &lt;TextView android:id="@+id/notification" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/minute" android:layout_marginLeft="41dp" android:layout_marginTop="47dp" android:text="@string/Notifications" android:textSize="20sp" /&gt; &lt;TextView android:id="@+id/time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/notification" android:layout_below="@+id/mile" android:layout_marginTop="62dp" android:text="@string/Time" /&gt; &lt;Spinner android:id="@+id/distanceview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/time" android:layout_alignTop="@+id/distance" android:layout_marginLeft="22dp" android:layout_toRightOf="@+id/mile" /&gt; &lt;Spinner android:id="@+id/timeview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/notification" android:layout_alignLeft="@+id/distanceview" android:layout_alignTop="@+id/time" /&gt; &lt;CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/timeview" android:layout_centerVertical="true" android:layout_marginLeft="24dp" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>and my java code</p> <pre><code>public class SettingsActivity extends SherlockActivity implements AdapterView.OnItemSelectedListener { private TextView distance, time; private Spinner spin; String spin_val; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings); addDistanceRadioButtons(); addTimeRadioButtons(); } public void addDistanceRadioButtons() { spin = (Spinner) findViewById(R.id.distanceview); final String[] item = { "0.1", "0.2", "0.4", "0.6", "0.8", "1.0", "1.2" } spin.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int position, long id) { // TODO Auto-generated method stub spin_val = item[position]; } @Override public void onNothingSelected(AdapterView&lt;?&gt; arg0) { // TODO Auto-generated method stub } }); ArrayAdapter&lt;String&gt; spin_adapter = new ArrayAdapter&lt;String&gt;(getBaseContext(), R.layout.settings, item); spin.setAdapter(spin_adapter); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload