我正在尝试使用fragment
使用Spinner
隐藏和显示,但我不知道如何执行此操作。但是当我使用buttons
时,我没有任何问题
任何想法如何制作这个?
这是我的代码:
public void Spinners() {
Connection connect = ConnectorClass.CONN();
try {
if (connect == null) {
Toast.makeText(getApplicationContext(), "NULL", Toast.LENGTH_LONG).show();
} else {
String query = "select window_number from window_info";
PreparedStatement stmt = connect.prepareStatement(query);
rs = stmt.executeQuery();
ArrayList<String> data = new ArrayList<String>();
while (rs.next()) {
String id = rs.getString("window_number");
data.add(id);
}
ArrayAdapter NoCoreAdapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, data);
spinner1.setAdapter(NoCoreAdapter);
}
} catch
(SQLException e) {
e.printStackTrace();
}
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
windows = spinner1.getSelectedItem().toString();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.animator.fade_in,
android.R.animator.fade_out);
if(windows == "Window One"){
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
答案 0 :(得分:0)
做这样的事情。
public void Spinners() {
Connection connect = ConnectorClass.CONN();
try {
if (connect == null) {
Toast.makeText(getApplicationContext(), "NULL", Toast.LENGTH_LONG).show();
} else {
String query = "select window_number from window_info";
PreparedStatement stmt = connect.prepareStatement(query);
rs = stmt.executeQuery();
ArrayList<String> data = new ArrayList<String>();
while (rs.next()) {
String id = rs.getString("window_number");
data.add(id);
}
ArrayAdapter NoCoreAdapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, data);
spinner1.setAdapter(NoCoreAdapter);
}
} catch
(SQLException e) {
e.printStackTrace();
}
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
windows = spinner1.getSelectedItem().toString();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.animator.fade_in,
android.R.animator.fade_out);
if(windows == "Window One"){
ft.replace(R.id.container,new WindowOneFragment());
ft.commit();
//Container is the Frame layout in which you want to add the fragment and WindowOneFragment is the fragment, you want to place there.
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}