所以我想制作我的Drop-down微调器< item>进入MYSQL数据库。 当这个< item>进入数据库,我想要列表< item>从下拉列表中消失。在我的情况下是否可能?因为我从strings.xml中插入了我的微调器项。
这是strings.xml
<resources>
<string name="app_name">Konser Futsal</string>
<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_password">Password (optional)</string>
<string name="action_sign_in">Sign in or register</string>
<string name="action_sign_in_short">Sign in</string>
<string name="error_invalid_email">This email address is invalid</string>
<string name="error_invalid_password">This password is too short</string>
<string name="error_incorrect_password">This password is incorrect</string>
<string name="error_field_required">This field is required</string>
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
<string-array name="android_layout_arrays">
<item>Pilih Jam</item>
<item>10:00</item>
<item>11:00</item>
<item>12:00</item>
<item>13:00</item>
<item>14:00</item> // i want to make these item get into MySQL DB.
<item>15:00</item> // when the "submit" button is clicked .
<item>16:00</item> // then after submitted,the next time
<item>17:00</item> // they check,the previous selected item is
<item>18:00</item> // disappear from the drop-down list
<item>19:00</item>
<item>20:00</item>
<item>21:00</item>
<item>22:00</item>
<item>23:00</item>
</string-array>
<string-array name="android_layout_arrays2">
<item>Pilih Durasi</item>
<item>1 jam</item>
<item>2 jam</item>
<item>3 jam</item>
</string-array>
这里是ReserveActivity.java代码
public class ReserveActivity extends AppCompatActivity {
private Spinner spinner1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reserve);
spinner1 = (Spinner) findViewById(R.id.spinner);
spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
}
public class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener {
String firstItem = String.valueOf(spinner1.getSelectedItem());
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if (firstItem.equals(String.valueOf(spinner1.getSelectedItem()))) {
// ToDo when first item is selected
} else {
Toast.makeText(parent.getContext(),
"Kamu memilih : " + parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_LONG).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg) {
}
}
}
或者我是否需要更改微调器的工作方式?因为我不知道如何将这些项目插入数据库并从下拉列表中消失。
答案 0 :(得分:0)
Using .xml file through inserted an array :
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:entries="@array/android_layout_arrays" />