如何设置“提示文本”对于微调器? [英] How to set "hint text" for spinner?

查看:193
本文介绍了如何设置“提示文本”对于微调器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据库中的微调器的值。我很困惑为Spinner添加提示,我在SO中关注了一些帖子,但我对这个地方很震惊,我试过这个

The value of the Spinner from Database. I am confusing to add hint for Spinner, I followed some posts in SO but i am struck with this place and I Tried this

    Spinner sp = (Spinner)findViewById(R.id.spinner); 
    sp.setSelection(pos);

该仓位有整数值所以我给它作为头寸的整数值,我也尝试用getCount ()内部的setSeletction()方法

the position have Integer value so i give it as a Integer value for position,also i try with getCount() inside of setSeletction() method

main.java

main.java

    //spinner for customer
        sp=(Spinner)findViewById(R.id.spinner);
        adapter=new ArrayAdapter<String>(this,R.layout.spinner_layout,R.id.txt,listItems);
        sp.setAdapter(adapter);
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sales_order);
        cus_name = (Spinner) findViewById(R.id.spinner);//customer spinner

        // Permission StrictMode
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

        //spinner for customer
        sp=(Spinner)findViewById(R.id.spinner);
        adapter=new ArrayAdapter<String>(this,R.layout.spinner_layout,R.id.txt,listItems);
        sp.setAdapter(adapter);


    }

private class BackTask extends AsyncTask<Void,Void,Void> {
        ArrayList<String> list;
        protected void onPreExecute(){
            super.onPreExecute();
            list=new ArrayList<>();
        }
        protected Void doInBackground(Void...params){
            InputStream is=null;
            String result="";
            try{
                HttpClient httpclient=new DefaultHttpClient();
                HttpPost httppost= new HttpPost("http://IP/web_services/customer_spinner.php");
                HttpResponse response=httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                // Get our response as a String.
                is = entity.getContent();
            }catch(IOException e){
                e.printStackTrace();
            }

            //convert response to string
            try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"));
                String line = null;
                while ((line = reader.readLine()) != null) {
                    result+=line;
                }
                is.close();
                //result=sb.toString();
            }catch(Exception e){
                e.printStackTrace();
            }
            // parse json data
            try{
                JSONObject object = new JSONObject(result);
                JSONArray jArray = object.getJSONArray("cus_Name");
                //JSONArray jArray =new JSONArray(result);
                for(int i=0;i<jArray.length();i++){
                    JSONObject jsonObject=jArray.getJSONObject(i);
                    // add interviewee name to arraylist
                    list.add(jsonObject.getString("cus_Name"));
                }
            }
            catch(JSONException e){
                e.printStackTrace();
            }
            return null;
        }
        protected void onPostExecute(Void result){
            listItems.addAll(list);
            adapter.notifyDataSetChanged();
        }
    }


推荐答案

那里很多方式:

1。) Android Hint Spinner

在build.gradle文件中使用此依赖项。

Use this dependency in build.gradle file.

dependencies {
    compile 'me.srodrigo:androidhintspinner:1.0.0'
}

输出:

了解更多详情请访问: https://github.com/srodrigo/Android-Hint-Spinner

for more detail visit this : https://github.com/srodrigo/Android-Hint-Spinner

2。)第二种方式

访问此处:
https://github.com/ravivyas84/AndroidSpinne rHint

这篇关于如何设置“提示文本”对于微调器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆