2013-09-26 1 views
0

안녕하세요,이 SimpleAdapter를 ListView에 일부 알림을 표시하기 위해 사용하고 있습니다. 이러한 알림은 ArrayList localist에 있습니다.Android : SimpleAdapter 오류

SimpleAdapter adapter = new SimpleAdapter(this,localist, R.layout.rss_list_item,new String[] {"title","pubDate"},new int[] {R.id.title, R.id.pubDate }); 
    final ListView lv = (ListView) findViewById(android.R.id.list); 
    lv.setAdapter(adapter); 

것은 그것이 나에게 첫 번째는 localist에있다 나가요 세 가지 오류를 표시하고 "localist이 변수에 해결 될 수 없다"라는 것입니다 : 여기에 코드입니다.

두 번째 및 세 번째이다

lv.setAdapter(adapter); 

라는 점에서 하나의 "토큰은, 잘못 구조체 (들)에 대한 구문 오류"와 괄호 그 내부 어댑터에서 다른에서 "토큰 구문 오류", "이 토큰 다음에 VariableDeclaratorId가 필요합니다." 두 번째 오류와 세 번째 오류는 첫 번째 오류 때문에 발생합니다. 이 문제를 해결하는 방법에 대해 아이디어가 있습니까?

편집 : 귀하의 의견에서

protected Integer doInBackground(Void... params) { 
     ArrayList<HashMap<String, String>> localist = new ArrayList<HashMap<String, String>>(); 
     String xml = ParseXMLmethods.getXML(); 
     Document doc = ParseXMLmethods.XMLfromString(xml); 
     if (doc != null) { 
     NodeList children = doc.getElementsByTagName("item"); 
     ZERO_FLAG = false; 
     if (children.getLength() == 0) { 
     ZERO_FLAG = true; 
     publishProgress(); 
     } 
     for (int i = 0; i < children.getLength(); i++) { 
     HashMap<String, String> map = new HashMap<String, String>(); 
     Element e = (Element) children.item(i); 
     map.put("title", ParseXMLmethods.getValue(e, "title")); 
     map.put("pubDate", ParseXMLmethods.getValue(e, "pubDate")); 
     map.put("link", ParseXMLmethods.getValue(e, "link")); 
     map.put("description",ParseXMLmethods.getValue(e, "description")); 
     localist.add(map); 

     } 
+0

더 많은 코드를 보여주세요. 지역 주의자를 어디에서 정의하고 만드나요? – SimonSays

+0

@ SimonSays here go – SoCo

+0

이 사이트는'localist'를 사용하려고하는 유일한 장소입니까? – codeMagic

답변

2

가, 내가 무슨 일이 일어나고 있는지 볼 생각하십시오 localist 선언하고 여기에 다른 활동 에 생성됩니다 코드입니다. Asynctask이 (가) Adapter과 다른 파일에있는 것 같습니다. 이 문제를 해결할 수있는 몇 가지 방법이 있습니다. 하나는 작업이 완료되면 에 변수를 설정하기 위해 interface을 사용하는 것입니다.

See this answerAsyncTask에 대해 interface을 만듭니다.

더 간단한 방법은 Adapter 인 내부 클래스를 으로 만들고 localist을 해당 클래스의 멤버 변수가되게하여 둘 다 액세스 할 수 있도록하는 것입니다. 그런 다음 AdapterListViewonPostExecute()에 설정할 수 있습니다.

+0

괜찮아! 당신의 시간과 인내심에 많이 감사합니다. – SoCo

+0

당신을 진심으로 환영합니다. 어떻게 진행되는지 알려주세요. – codeMagic

+0

여전히 작동하지 않습니다./올바르게 코드를 작성했는지 확인하기 위해 코드를 보낼 수 있습니까? – SoCo

관련 문제