i have set one spinner in my screen1 to select any of the spinner data from spinner and adding to my database. Now I have another screen2 of same spinner what i have in screen1 with same spinner data. I want to show the data what is added in database, in first index of the spinner in layout2, without reputation of data in the spinner?
我在screen1中设置了一个微调器,从微调器中选择任何微调器数据并添加到我的数据库中。现在我有另一个与screen1相同的微调器的screen2,它具有相同的微调器数据。我想在layout2中的微调器的第一个索引中显示数据库中添加的数据,而没有微调器中的数据声誉?
In Screen 1
在屏幕1中
organizer = (Spinner) findViewById(R.id.orgainzer);
organizer.setAdapter(new ArrayAdapter<String>(Appoinment_Activity.this,android.R.layout.simple_spinner_dropdown_item,organizerspin));
// Spinner on item click listener
organizer.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
// TODO Auto-generated method stub
try{
getorganizer= organizer.getSelectedItem().toString();
}catch(ArrayIndexOutOfBoundsException e){}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
In Screen 2 with same code what i mentioned above, i just code like this
在屏幕2中使用与上面提到的相同的代码,我只是这样编码
editapporganizerspin.add(0,"Store_organizer");
if i do like this data is repeated in spinner
如果我喜欢这个数据在微调器中重复
1 个解决方案
#1
0
private int getIndex(Spinner spinner, String myString){
int index = 0;
for (int i=0;i<spinner.getCount();i++){
if (spinner.getItemAtPosition(i).equals(myString)){
index = i;
}
}
return index;
}
Use this function after setting the adapter to compare the spinner values and swap it in index zero if the value is in spinner
设置适配器后使用此功能比较微调器值,如果值在微调器中,则在索引零处交换它
#1
0
private int getIndex(Spinner spinner, String myString){
int index = 0;
for (int i=0;i<spinner.getCount();i++){
if (spinner.getItemAtPosition(i).equals(myString)){
index = i;
}
}
return index;
}
Use this function after setting the adapter to compare the spinner values and swap it in index zero if the value is in spinner
设置适配器后使用此功能比较微调器值,如果值在微调器中,则在索引零处交换它