我在我的程序中使用了一个旋转器,它从我的azure数据库中获取数据,但是当我单击下拉时,什么也不会发生。这是我的密码
try {
ConnectionHelper conStr = new ConnectionHelper();
connect = conStr.connectionclass();
String query = "select * from fabric";
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery(query);
ArrayList<String> data = new ArrayList<String>();
while (rs.next()) {
String id = rs.getString("FABRIC_NAME");
data.add(id);
}
String[] array = data.toArray(new String[0]);
ArrayAdapter NoCoreAdapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, data);
Fabric.setAdapter(NoCoreAdapter);
} catch (SQLException e) {
e.printStackTrace();
}
Fabric.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String name = Fabric.getSelectedItem().toString();
Toast.makeText(Calc_140_plain.this, name, Toast.LENGTH_SHORT)
.show();
}
public void onNothingSelected(AdapterView<?> parent) {
}
});我似乎也找不到LogCat中的错误
发布于 2018-09-30 12:40:13
确保数据数组有一些元素
while (rs.next()) {
String id = rs.getString("FABRIC_NAME");
data.add(id);
}
Log.d("data","size:"+data.size());检查数据后的打印大小不是空的。
试试这个:
ArrayAdapter NoCoreAdapter = new ArrayAdapter<String>(context,
android.R.layout.simple_list_item_1, data);而不是:
ArrayAdapter NoCoreAdapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, data);https://stackoverflow.com/questions/52577898
复制相似问题