本文介绍了我怎样才能加载的ListView动态取决于从微调价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个微调,编辑文字,按钮,在视图列表视图。我想我的加载从的ListView数据库上的微调值取决于。和我做对列表视图还添加操作。
我的怀疑是,我想知道我可以载入我的列表视图依赖于从微调的数据?
公共MyClass类扩展ListActivity实现OnClickListener {
DatabaseFAM分贝;
微调否;
串选择;
用户的EditText;
按钮btnAdd;
串strselected;
ArrayList的<串GT;名单=新的ArrayList<串GT;();
ArrayAdapter<串GT; adapterLV;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.myews);
DB =新DatabaseFAM(getApplicationContext());
initVar();
}
私人无效initAudit2Var(){
否=(微调)findViewById(R.id.station);
用户=(EditText上)findViewById(R.id.er);
btnAdd =(按钮)findViewById(R.id.btnAdd);
btnAdd.setOnClickListener(本);
adapterLV =新ArrayAdapter<串GT;(这一点,
android.R.layout.simple_list_item_multiple_choice,清单);
setListAdapter(adapterLV);
最后DatabaseFAM DB =新DatabaseFAM(getApplicationContext());
清单<串GT;站= db.getAllstation();
ArrayAdapter<串GT; stationAdapter =新ArrayAdapter<串GT;(
getApplicationContext(),android.R.layout.simple_spinner_item,
站);
stationAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
No.setAdapter(stationAdapter);
No.setOnItemSelectedListener(新OnItemSelectedListener(){
@覆盖
公共无效onItemSelected(适配器视图<>为arg0,ARG1查看,
INT ARG2,长ARG3){
选择= arg0.getItemAtPosition(
ARG2)的ToString();
list.clear();
清单= db.getTag(选择);
adapterLV.notifyDataSetChanged(); } @覆盖
公共无效onNothingSelected(适配器视图<>为arg0){ }
});
}
解决方案
= SP1(微调)findViewById(R.id.spinner1);
sp1.setOnItemSelectedListener(新OnItemSelectedListener(){ @覆盖
公共无效onItemSelected(适配器视图<>为arg0,ARG1查看,
INT POS,长ARG3){
//装入列表在这里
}}
I have a Spinner,Edit Text, Button and a List View in a View. I want to Load my ListView from database Depends on the value from spinner. and i'm doing add operation on List View also.
My Doubt is that i wanted to know how can i load my list view depends on the data from spinner?
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) {
}
});
}
解决方案
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
}}
这篇关于我怎样才能加载的ListView动态取决于从微调价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!