我在视图中有一个微调器、编辑文本、按钮和一个列表视图。我想从数据库加载我的 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) {
}
});
}