티스토리 뷰
스피너 예제
Spinner spModelList1;
protected void onCreate(Bundle savedInstanceState){
...
spModelList1 = (Spinner) findViewById(R.id.sp_modellist1);
spModelList1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
ModelIndex = i;
JSONObject jsonObj = ModelInfos.get(ModelIndex);
try {
etSNo1.setText(jsonObj.getString("SNo"));
etModelName1.setText(jsonObj.getString("ModelName"));
} catch (Exception e) {
Log.d(TAG, "[?-1] onItemSelected()");
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
ModelIndex = 0;
try {
JSONObject jsonObj = ModelInfos.get(ModelIndex);
etModelName1.setText(jsonObj.getString("ModelName"));
} catch (Exception e) {
Log.d(TAG, "[?-1] onNothingSelected()");
}
}
});
...
SetSpinnerItems(modelInfos);
}
private void SetSpinnerItems(JSONArray modelInfos) {
ModelInfos = new ArrayList<>();
...
for (JSONObject modelInfo : ModelInfos) {
try {
modelName = modelInfo.getString("ModelName");
spinnerItems.add(modelName);
ModelNames.add(modelName);
} catch (Exception e) {
continue;
}
}
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, spinnerItems);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spModelList1.setAdapter(spinnerAdapter);
}
반응형
'SWDesk > App' 카테고리의 다른 글
RecyclerVieiwTest02 (0) | 2021.11.06 |
---|---|
[Android] JSON String from Web (0) | 2021.10.09 |
[Android] HTTP POST Request (0) | 2021.08.22 |
[Android] Displaying AlertDialog (0) | 2021.08.14 |
[Android] Generating Beep (0) | 2021.07.31 |
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 전류
- 치매방지
- image
- 둎
- badp
- 허들
- Video
- 혁신과허들
- 티스토리챌린지
- 절연형
- 치매
- 전압전류모니터링
- 혁신
- 오블완
- Innovations&Hurdles
- ServantClock
- BSC
- 빌리언트
- 전압
- Decorator
- 아두이노
- 심심풀이치매방지기
- DYOV
- arduino
- 심심풀이
- 배프
- bilient
- Innovations
- Innovation&Hurdles
- Hurdles
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함