飞旋在android系统 [英] spinner in android

查看:240
本文介绍了飞旋在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要开发在Android中一个微调的例子。在这里,我用低于code:

 公共类InsertionExample延伸活动{
 私人最终字符串NAMESPACE =htt​​p://xcart.com;
私人最终字符串URL =htt​​p://192.168.1.168:8089/XcartLogin/services/update?wsdl;
私人最终字符串SOAP_ACTION =htt​​p://xcart.com/insertData;
私人最终字符串METHOD_NAME =insertData;
按钮btninsert;
字符串将selectedItem;静态最后弦乐KEY_NAME =订单ID;
静态最后弦乐KEY_STATUS =身份;
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.change_status);
    微调微调=(微调)findViewById(R.id.spinner1);
    btninsert =(按钮)findViewById(R.id.btn_insert1);
    btninsert.setOnClickListener(新View.OnClickListener(){
        公共无效的onClick(视图v){
             在意向= getIntent();
             字符串订单ID = in.getStringExtra(KEY_NAME);
             字符串状态= in.getStringExtra(KEY_STATUS);
 SoapObject要求=新SoapObject空间(namespace,METHOD_NAME);
            的PropertyInfo unameProp =新的PropertyInfo();
            unameProp.setName(状态); //在Web服务方法定义的变量名称
            unameProp.setValue(将selectedItem); //定义FNAME变量值
            unameProp.setType(为String.class); //定义变量的类型            request.addProperty(unameProp);
            的PropertyInfo idProp =新的PropertyInfo();
            idProp.setName(订单ID); //在Web服务方法定义的变量名称
            idProp.setValue(订单id); //定义FNAME变量值
            idProp.setType(为String.class); //定义变量的类型
            request.addProperty(idProp);              SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
              envelope.setOutputSoapObject(请求);
              HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);              尝试{
               androidHttpTransport.call(SOAP_ACTION,信封);
                  SoapPrimitive响应=(SoapPrimitive)envelope.getResponse();                 TextView的结果=(的TextView)findViewById(R.id.textView2);
                  result.setText(response.toString());
             }
           赶上(例外五){           }
              }
    });    //监听器连接到微调
    spinner.setOnItemSelectedListener(新MyOnItemSelectedListener());
    //动态生成的数据微调
    createSpinnerDropDown();}//添加到动物动态微调
私人无效createSpinnerDropDown(){    //从XML布局得到参考微调
    微调微调=(微调)findViewById(R.id.spinner1);    //动物的数组列表中的显示微调
    清单<串GT;名单=新的ArrayList<串GT;();
    在意向= getIntent();    字符串状态= in.getStringExtra(KEY_STATUS);
    list.add(状态);
    list.add(Q);
    list.add(P);
    list.add(F);
    list.add(I);
    list.add(C);    //从字符串数组创建一个ArrayAdaptar
    ArrayAdapter<串GT;适配器=新ArrayAdapter<串GT;(这一点,
            android.R.layout.simple_spinner_item,清​​单);
    //设置下拉列表视图
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //一个ArrayAdapter设置为微调
    spinner.setAdapter(适配器);
    adapter.notifyDataSetChanged();
    //监听器连接到微调
    spinner.setOnItemSelectedListener(新MyOnItemSelectedListener());}   公共类MyOnItemSelectedListener实现OnItemSelectedListener {    公共无效onItemSelected(适配器视图<>母公司,观景,INT POS,长I​​D){         将selectedItem = parent.getItemAtPosition(POS)的ToString();       }
    @覆盖
    公共无效onNothingSelected(适配器视图<>为arg0){
        // TODO自动生成方法存根    }    }    公共无效onNothingSelected(适配器视图<>母公司){
        // 没做什么。
    }
}

下面以下列表上微调框添加:

 列表<串GT;名单=新的ArrayList<串GT;();
    在意向= getIntent();    字符串状态= in.getStringExtra(KEY_STATUS);
    list.add(状态);
    list.add(Q);
    list.add(P);
    list.add(F);
    list.add(I);
    list.add(C);

下面的状态从previous活动value.other列表默认Q,则显示P,F,I和C.because第一个列表previous只有状态得到。因此,只有我要补充的地位第一次在这里。

现在我的问题是,

现在我的previous状态C表示我的微调框要显示的格式如下:

下面的第一个和最后一个值只显示温度。因此,C值在我的微调中提供的两倍。
这是我的问题。在这里,我要的先添加previous地位,也同时previous状态没有添加别的地方。我怎么能在这里发展。请给我一些解决方案。对于例如;

如果我的previous状态是P,则所显示的第一个值是P和还示出Q,P,F,I,C。因此,这里P被显示的2倍。那么,如何解决这个错误。

编辑:

  list.add(状态);
    list.add(Q);
    list.add(P);
    list.add(F);
    list.add(I);
    list.add(C);
    对于(i = 0; I< List.length的数字();我++){
        如果(list.get(ⅰ).equals(状态)){
                list.remove(list.get(I));
        }
   }

在这里,我得到下面的错误:
的方法长度()是未定义的类型
 列表

我怎样才能解决这个错误。请帮我


解决方案

  list.add(状态);
list.add(Q);
list.add(P);
list.add(F);
list.add(I);
list.add(C);
INT位置= -1;
    对于(i = 0; I<则为list.size();我++){
        如果(list.get(ⅰ).equals(状态)){
                位置=我;
        }
   }
如果(仓位大于0)
   list.removeAt(位置);

这如果如果(仓位大于0)
       list.removeAt(位置);
奖励,如果状态在列表中,也不会被删除。它将的Stille在列表的顶部。

Hi I need to develop a spinner example in android. Here I have used below code:

 public class InsertionExample extends Activity {
 private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://192.168.1.168:8089/XcartLogin/services/update?wsdl";
private final String SOAP_ACTION = "http://xcart.com/insertData";
private final String METHOD_NAME = "insertData";
Button btninsert;
String selectedItem;

static final String KEY_NAME = "orderid";
static final String KEY_STATUS = "status";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.change_status);
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    btninsert = (Button)findViewById(R.id.btn_insert1);
    btninsert.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
             Intent in = getIntent();
             String orderid = in.getStringExtra(KEY_NAME);
             String status = in.getStringExtra(KEY_STATUS);
 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            PropertyInfo unameProp =new PropertyInfo();
            unameProp.setName("Status");//Define the variable name in the web service method
            unameProp.setValue(selectedItem);//Define value for fname variable
            unameProp.setType(String.class);//Define the type of the variable

            request.addProperty(unameProp);
            PropertyInfo idProp =new PropertyInfo();
            idProp.setName("Orderid");//Define the variable name in the web service method
            idProp.setValue(orderid);//Define value for fname variable
            idProp.setType(String.class);//Define the type of the variable
            request.addProperty(idProp);



              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
              envelope.setOutputSoapObject(request);
              HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

              try{
               androidHttpTransport.call(SOAP_ACTION, envelope);
                  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

                 TextView result = (TextView) findViewById(R.id.textView2);
                  result.setText(response.toString());
             }
           catch(Exception e){

           }
              }
    });

    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
    //Dynamically generate a spinner data 
    createSpinnerDropDown();

}

//Add animals into spinner dynamically
private void createSpinnerDropDown() {

    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

    //Array list of animals to display in the spinner
    List<String> list = new ArrayList<String>();
    Intent in = getIntent();

    String status = in.getStringExtra(KEY_STATUS);
    list.add(status);
    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");

    //create an ArrayAdaptar from the String Array
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    //set the view for the Drop down list
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //set the ArrayAdapter to the spinner
    spinner.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

}

   public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

         selectedItem = parent.getItemAtPosition(pos).toString();

       }


    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }



    }

    public void onNothingSelected(AdapterView<?> parent) {
        // Do nothing.
    }
}

Here the following List is added on spinner box:

 List<String> list = new ArrayList<String>();
    Intent in = getIntent();

    String status = in.getStringExtra(KEY_STATUS);
    list.add(status);
    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");

Here the status is getting from previous activity value.other list is default Q,P,F,I and C.because the first list is displayed previous status only. So only I have to added status first here.

Now my problem is,

Now my previous status is C means my spinner box have to displayed following format:

Here the first and last values are displayed C only. So the C value is available twice on my spinner box. This is my problem. Here I want to add the previous status first and also same time the previous status is not added another place. How can I develop here. Please give me some solutions. For e.g;

If my previous status is P, then the first value displayed is P and also shows Q,P,F,I,C. So here P is displayed 2 times. So how can I resolve this error.

EDIT:

list.add(status);
    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");
    for(i=0;i<list.length();i++){
        if(list.get(i).equals(status)) {
                list.remove(list.get(i));
        }
   }

Here I get the below error: The method length() is undefined for the type List

How can I resolve this error. Please help me

解决方案

list.add(status);
list.add("Q");
list.add("P");
list.add("F");
list.add("I");
list.add("C");
int position = -1;
    for(i=0;i<list.size();i++){
        if(list.get(i).equals(status)) {
                position = i;
        }
   }
if(position>0)
   list.removeAt(position);

This ifif(position>0) list.removeAt(position); grants that if status is in your list, it will not be removed. It will stille be at the top of the list.

这篇关于飞旋在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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