2013-03-26 53 views
1

嗨大家好, 我有三个微调器,我想根据第一个微调器值改变第二微调器值的变化,第三微调器根据第二个微调器的值改变所有的值,从数据库中显示。我正在使用ArrayAdapter。我正在搜索最近两周。但我没有得到解决方法善意帮助我,我没时间了。微调值根据父微调值的变化而变化

+0

发布您的代码... – Tushar 2013-03-26 06:05:13

+0

亲爱的所有人请帮助我,我可能会耗尽时间。请给出完整的来源来执行该程序pls – venkateswaran 2013-03-26 06:06:50

+0

你试过了什么? – rajeshwaran 2013-03-26 06:08:43

回答

2

可能,这将帮助,

ArrayAdapter<String> secondspinnerAdapter; 
ArrayAdapter<String> firstspinnerAdapter = new ArrayAdapter<String>(
       MainActivity.this, android.R.layout.simple_spinner_item, 
       firstspinnervalue); 
     first_spinner.setAdapter(firstspinnerAdapter); 
     firstspinnerAdapter 
       .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 


firstspinner.setOnItemSelectedListener(new OnItemSelectedListener() { 

      @Override 
      public void onItemSelected(AdapterView<?> arg0, View arg1, 
        int arg2, long arg3) { 
       // TODO Auto-generated method stub 

        // get data from database add to arraylist 

         secondspinnerAdapter = new 
         ArrayAdapter<String>(mainActivity.this, 
         android.R.layout.simple_spinner_item, arraylistvalue); 
         second_spinner.setAdapter(secondspinnerAdapter); 
         second_spinner.setSelection(arg2, false); 
         secondspinnerAdapter.setDropDownViewResource 
         (android.R.layout.simple_spinner_dropdown_item); 

      } 

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

      } 
     }); 

第一微调项被选中,然后从数据库中获取数据并填入数组列表并设置秒数。

同样的方式选择第二个微调项目。

+0

@rajehwaran我从你的帮助中得到了答案谢谢你的帮助 – venkateswaran 2013-04-02 04:08:45

3

你要只是不设置适配器,如:

package com.example.mapsdemo; 

import java.util.ArrayList; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemSelectedListener; 
import android.widget.ArrayAdapter; 
import android.widget.Spinner; 

public class MainActivity extends Activity { 

    private Spinner spin1; 
    private Spinner spin2; 

    ArrayList<String> a = new ArrayList<String>(); 
    ArrayList<String> b = new ArrayList<String>(); 
    ArrayList<String> c = new ArrayList<String>(); 

    // private ImageView imageView; 

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

     spin1 = (Spinner) findViewById(R.id.spinner1); 
     spin2 = (Spinner) findViewById(R.id.spinner2); 

     fillarray(); 

     spin1.setAdapter(new ArrayAdapter<String>(MainActivity.this, 
       android.R.layout.simple_dropdown_item_1line, a)); 
     /* 
     * spin2.setAdapter(new ArrayAdapter<String>(MainActivity.this, 
     * android.R.layout.simple_dropdown_item_1line, b)); 
     */ 

     spin1.setOnItemSelectedListener(new OnItemSelectedListener() { 

      @Override 
      public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, 
        long arg3) { 
       // TODO Auto-generated method stub 
       if (pos == 0) { 
        spin2.setAdapter(new ArrayAdapter<String>(
          MainActivity.this, 
          android.R.layout.simple_dropdown_item_1line, b)); 
       } else { 
        spin2.setAdapter(new ArrayAdapter<String>(
          MainActivity.this, 
          android.R.layout.simple_dropdown_item_1line, c)); 
       } 
      } 

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

      } 
     }); 
    } 

    private void fillarray() { 
     // TODO Auto-generated method stub 
     a.clear(); 
     a.add("a"); 
     a.add("b"); 
     a.add("c"); 
     a.add("d"); 
     a.add("e"); 

     b.clear(); 
     b.add("1"); 
     b.add("2"); 
     b.add("3"); 
     b.add("4"); 

     c.clear(); 
     c.add("Android"); 
     c.add("ios"); 
    } 

} 

您的布局文件,如:

<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" > 

    <Spinner 
     android:id="@+id/spinner1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="40dp" /> 

    <Spinner 
     android:id="@+id/spinner2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/spinner1" 
     android:layout_marginTop="80dp" /> 

</RelativeLayout>