안녕하세요 XML 및 구문 분석 데이터를 다운로드하고 있습니다. 스피너에 데이터를 추가하고 싶습니다. 응용 프로그램을 실행할 때마다 데이터가 업데이트됩니다.xml에서 스피너에 데이터를 동적으로 추가하는 방법
public class Main extends ListActivity {
TextView valueTextView;
HashMap<String, String> name=null;
private HashMap<String, String> array_spinner[];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main)
ArrayList<HashMap<String, String>>mylist = new ArrayList<HashMap<String, String>>();
String xml = XMLfunctions.getXML();
Document doc = XMLfunctions.XMLfromString(xml);
NodeList nodes = doc.getElementsByTagName("Table");
Toast.makeText(Main.this, "ID '" + nodes.getLength(),Toast.LENGTH_LONG).show();
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put("id", XMLfunctions.getValue(e, "id"));
map.put("name", "Name:" + XMLfunctions.getValue(e, "name"));
map.put("Score", "Score: " + XMLfunctions.getValue(e, "score"));
mylist.add(map);
}
valueTextView = (TextView)findViewById(R.id.selected);
Spinner s = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}
그것의 불완전 코드 나는 당신에게
Abhishek
감사 SpinnerAdapter 사람이 나에게 도와주세요 적용하는 방법을 모르는 나는 당신의 해시 맵을 대신 배열을 만들 것
내리스트 안의 데이터를 가져 오는 중 ... ...? –
@lalit : 예 mylist에 데이터를 가져 와서 현재 ListView에 데이터를 성공적으로 표시했습니다.하지만 애플리케이션 요구 사항이 업데이트 될 때마다 데이터가 동적이기 때문에 필자는 Spinner에 구문 분석 데이터를 필요로했습니다. –
글쎄, 당신 mylist는 ArrayList에 데이터를 넣고 회 전자에 추가한다고 말하는지도가있는 arraylist입니다. –