0

enter image description here

public class MainActivity extends Activity {

String[] DayOfWeek = { "Select Item", "1", "2", "3", "4", "5", "6" };

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

    Spinner mySpinner = (Spinner) findViewById(R.id.spinner);
    mySpinner.setAdapter(new MyCustomAdapter(MainActivity.this,
            R.layout.row, DayOfWeek));
}

public class MyCustomAdapter extends ArrayAdapter<String> {

    public MyCustomAdapter(Context context, int textViewResourceId,
            String[] objects) {
        super(context, textViewResourceId, objects);
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getDropDownView(int position, View convertView,
            ViewGroup parent) {
        // TODO Auto-generated method stub
        return getCustomView(position, convertView, parent);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        return getCustomView(position, convertView, parent);
    }

    public View getCustomView(int position, View convertView,
            ViewGroup parent) {
        // TODO Auto-generated method stub
        // return super.getView(position, convertView, parent);

        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.row, parent, false);
        TextView label = (TextView) row.findViewById(R.id.weekofday);
        label.setText(DayOfWeek[position]);

        ImageView icon = (ImageView) row.findViewById(R.id.icon);

        if (DayOfWeek[position] == "Sunday") {
            icon.setImageResource(R.drawable.icon);
        } else {
            icon.setImageResource(R.drawable.icongray);
        }

        return row;
    }
}

}

here is my code i am able to display value in spinner but i want display Select item only on Textview not in Value while its displaying in value also tell me how to remove that please see screen and tell me how to remove that

Edge
  • 925
  • 5
  • 15
  • 31

2 Answers2

1

One simple solution is:
a) Modify the array to

String[] DayOfWeek = { "1", "2", "3", "4", "5", "6" };

b) Call mySpinner.setPromptId() and set a string reosurceId with value "Select item".

For having the "Select item" only when the drop-down is not opened or closed , follow this link How to make an Android Spinner with initial text "Select One"?

Community
  • 1
  • 1
thepace
  • 2,221
  • 1
  • 13
  • 21
0
ListPopupWindow numberList;
TextView spDays;
ArrayList<Map<String, String>>() listTrans;

in oncreate spDays.setonclicklistner(this);spDays.setText("Select");
setNumberListSpinnerView();
in onclick(){
  when spDays clicked :- numberList.show();
}


void setNumberListSpinnerView() {

    numberList= new ListPopupWindow(this);
    numberList.setAnchorView(spDays);

    numberList.setOnItemClickListener((new AdapterView.OnItemClickListener() {
        @Override
        getListItem();
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Map map = listTrans.get(position);
            spDays.setText(map.get("circle_name").toString());
            circle_name = map.get("circle_name") + "";
            circle_id = map.get("circle_id").toString();
            circleList.dismiss();
            Log.d("Circle id:", circle_id + "");
            getRetails();

        }
    }));
}


void getListItem(){
    String[] numbers = {"1","2","3","4","5","6"};
    listTrans = new ArrayList<Map<String, String>>();
    LinkedHashMap<String, String> tran = new LinkedHashMap<String, String>();
    for (String number : numbers) {
        tran.put("numbers", number);
        listTrans.add(tran);
    }
    SimpleAdapter adapter = new SimpleAdapter(AddRetailSurvey.this, listTrans,
            android.R.layout.simple_spinner_dropdown_item,
            new String[]{"numbers"},
            new int[]{android.R.id.text1});
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    numberList.setAdapter(adapter);
}

Change the code with your requirement, check and let me know if you face any problem. The best part of this technique you can change the text color. Thanks :)

Biswajit
  • 1,829
  • 1
  • 18
  • 33