1

我在视图中有一个微调器、编辑文本、按钮和一个列表视图。我想从数据库加载我的 ListView 取决于微调器的值。我也在列表视图上进行添加操作。

我的疑问是我想知道如何加载我的列表视图取决于来自微调器的数据?

public class myClass extends ListActivity implements OnClickListener {
DatabaseFAM db;
Spinner No;
String Selected;
EditText user;
Button btnAdd;
String strselected;
ArrayList<String> list =new ArrayList<String>();
ArrayAdapter<String> adapterLV;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myews);
    db = new DatabaseFAM(getApplicationContext());
    initVar();
}


private void initAudit2Var() {
    No = (Spinner) findViewById(R.id.station);
    user = (EditText) findViewById(R.id.er);
    btnAdd = (Button) findViewById(R.id.btnAdd);
    btnAdd.setOnClickListener(this);
    adapterLV = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_multiple_choice, list);
    setListAdapter(adapterLV);
    final DatabaseFAM db = new DatabaseFAM(getApplicationContext());
    List<String> station = db.getAllstation();
    ArrayAdapter<String> stationAdapter = new ArrayAdapter<String>(
            getApplicationContext(), android.R.layout.simple_spinner_item,
            station);
    stationAdapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    No.setAdapter(stationAdapter);
    No.setOnItemSelectedListener(new OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    Selected = arg0.getItemAtPosition(
                            arg2).toString();   
                    list.clear();
                    list=db.getTag(Selected);
                    adapterLV.notifyDataSetChanged();

                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {

                }
            });
}
4

3 回答 3

0
          sp1 = (Spinner)findViewById(R.id.spinner1);
          sp1.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int pos, long arg3) {
                // Load your list here
                }}
于 2012-10-19T11:25:33.680 回答
0
  1. 将 onItemSelected 事件添加到您的微调器。
  2. 根据选择的值,使用所需的数据修改您的 listView
  3. 在列表视图上使用 Datasetchanged 事件
于 2012-10-19T11:24:37.770 回答
0

您应该在 Spinner 的 Item selection 处设置 ListView 的 Adapter ....

        mSpinnerLangAttrValue.setOnItemSelectedListener(new OnItemSelectedListener() {

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

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

        }
    });
于 2012-10-19T11:22:52.997 回答