Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have this </p> <p><img src="https://i.stack.imgur.com/SWB9d.png" alt="enter image description here"></p> <p>and this</p> <p><img src="https://i.stack.imgur.com/vS17u.png" alt="enter image description here"></p> <p>with these code of xml</p> <p>xml for adapter named spinadapt.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="30dp" android:background="#fff" &gt; &lt;TextView android:id="@+id/tvCust" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_toLeftOf="@+id/radioButton1" android:gravity="left|center_vertical" android:textColor="#000" android:textSize="15sp" /&gt; &lt;RadioButton android:layout_width="wrap_content" android:layout_height="30dp" android:layout_alignParentRight="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>and main layout named activity_main.xml</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;TextView android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:hint="Select item" android:background="@drawable/spin"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>and java code is class named MainActivity.java</p> <pre><code>public class MainActivity extends Activity { Spinner sp; TextView tv; String[] counting={"One","Two","Three","Four"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=new Spinner(this); tv=(TextView)findViewById(R.id.spinner1); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { sp.performClick(); } }); sp.setAdapter(new Adapter(MainActivity.this, counting)); sp.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { tv.setText(counting[arg2]); } @Override public void onNothingSelected(AdapterView&lt;?&gt; arg0) { } }); } } </code></pre> <p>and adapter class named Adapter.java</p> <pre><code>public class Adapter extends BaseAdapter { LayoutInflater inflator; String[] mCounting; public Adapter( Context context ,String[] counting) { inflator = LayoutInflater.from(context); mCounting=counting; } @Override public int getCount() { return mCounting.length; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = inflator.inflate(R.layout.spinadapt, null); TextView tv = (TextView) convertView.findViewById(R.id.tvCust); tv.setText(Integer.toString(position)); return convertView; } } </code></pre> <p>this is working perfect </p> <p>hope this will help</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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