我怎样才能加载的ListView动态地依赖于从微调价值(How Can i Load ListVie

2019-10-17 08:24发布

我有一个微调,编辑文字,按钮,在视图列表视图。 我想我的加载从的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) {

                }
            });
}

Answer 1:

你应该在微调的项目选择设置的ListView适配器....

        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

        }
    });


Answer 2:

  1. onItemSelected事件添加到您的微调。
  2. 取决于seletion的值修改您的ListView与所需的数据
  3. 使用Datasetchanged事件的列表视图


Answer 3:

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


文章来源: How Can i Load ListView Dynamically Depends on the Value from Spinner