在系统中,当我选择msg默认情况下,msg显示在spinner上。我需要这个项目那些选择项目只显示spinner。如果我更改项目不显示前一个选择项目显示在微调器上。 的 list.java
Spinner sp1;
TextView entry;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
sp1=(Spinner) findViewById(R.id.spinner1);
entry = (TextView)findViewById(R.id.TextView123);
getFilesnames();
}
private void getFilesnames() {
// TODO Auto-generated method stub
String[] filenames=getApplicationContext().fileList();
List<String> list=new ArrayList<String>();
for(int i=0;i<filenames.length;i++){
list.add(filenames[i]);
}
ArrayAdapter<String> filenameAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
sp1.setAdapter(filenameAdapter);
}
public void onClick(View v) {
// TODO Auto-generated method stub
String selectFile = String.valueOf(sp1.getSelectedItem());
openFile(selectFile);
}
private void openFile(String selectFile) {
// TODO Auto-generated method stub
String value = "";
FileInputStream fis;
try {
fis = openFileInput(selectFile);
byte[] input = new byte[fis.available()];
while(fis.read(input) != -1){
value += new String(input);
}
fis.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
entry.setText(value);
}
答案 0 :(得分:0)
检查绑定后list
是否有值,如下面的代码:
private void getFilesnames() {
// TODO Auto-generated method stub
String[] filenames=getApplicationContext().fileList();
List<String> list=new ArrayList<String>();
for(int i=0;i<filenames.length;i++){
list.add(filenames[i]);
}
/***
check here list has value or not
***/
if(list.size() <= 0) {
list.add("You string.....");
}
ArrayAdapter<String> filenameAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
sp1.setAdapter(filenameAdapter);
}