2012-12-05 2 views
1

나는 개발에 어려움을 겪고있다. Eclipse JUNO를 사용한 첫 안드로이드 애플리케이션이다. ListActivity에서 Listview를 public static 변수로 채우고 올바르게 할당하려고합니다 (디버거에서 확인). 문제는 목록보기에 올바른 행 수가 표시되지만 빈 데이터가 표시된다는 것입니다.안드로이드 : 빈 데이터가 포함 된 ListView

Grilla.java

import android.os.Bundle; 
import android.app.ListActivity; 
import android.view.View; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 

public class Grilla extends ListActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     try 
     { 
      SimpleAdapter adapter = new SimpleAdapter(Grilla.this, VariablesPublicas.listado_grilla, R.layout.mylistrow, 
        VariablesPublicas.ColumnTags, new int[] {R.id.column1, R.id.column2}); 
      setListAdapter(adapter); 

      //getListView().setTextFilterEnabled(true); 
     } 
     catch(Exception e) { 
      System.out.println(e.toString()); 
     } 
    } 

    protected void onListItemClick(ListView l, View v, int position, long id) { 
      super.onListItemClick(l, v, position, id); 
      Object o = l.getItemAtPosition(position); 
      VariablesPublicas.itemSeleccionado = o.toString(); 
      finish(); 

    } 

} 

mylistrow.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TextView 
     android:id="@+id/column1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="1" 
     android:visibility="invisible" /> 

    <TextView 
     android:id="@+id/column2" 
     android:layout_width="fill_parent" 
     android:layout_height="34dp" 
     android:text="2" /> 

</LinearLayout> 

activity_grilla.xml (Grilla.java)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ListView 
     android:id="@+id/listView_grilla" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     tools:listitem="@layout/mylistrow" > 

    </ListView> 

</LinearLayout> 

주요 응용 프로그램 :

그는 내 코드입니다 :

public class Main extends Activity { 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     final Button btn_buscarobra = (Button) findViewById(R.id.btn_buscarobra); 

     btn_buscarobra.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       // Perform action on click 
       servicioweb WS = new servicioweb(); 
       try { 
        String obras = WS.ObtenerObras(""); 
        org.w3c.dom.Document doc = WS.XMLfromString(obras); 

        NodeList nodes = doc.getElementsByTagName("entry"); 

        //fill in the list items from the XML document 
        VariablesPublicas.listado_grilla = new ArrayList<HashMap<String, String>>(); 

        for (int i = 0; i < nodes.getLength(); i++) { 
         Element e = (Element)nodes.item(i); 
         HashMap<String, String> map = new HashMap<String, String>(); 
         map.put("id_obra", servicioweb.getValue(e, "IdObra")); 
         map.put("obra", servicioweb.getValue(e, "Obra")); 
         //VariablesPublicas.listado_grilla.(new String[] {servicioweb.getValue(e, "IdObra"), 
         //  }); 
         VariablesPublicas.listado_grilla.add(map); 

        } 
        VariablesPublicas.ColumnTags = new String[] {"#", "OBRA"}; 
        Intent listaObras = new Intent(Main.this, Grilla.class); 
        startActivityForResult(listaObras,0); 

       } catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
     }); 
    } 

listview에서 항목을 클릭하면 올바른 값이 반환됩니다.

감사합니다.

곤잘로.

+1

당신은 첫 번째 텍스트 뷰가 보이지 않는로 설정되어; 아마 그 중 하나의 텍스트가 두 번째보기를 밀어 내기에 충분히 길기 때문에 아무 것도 볼 수 없습니까? 'android : visibility = "invisible"'행을 지우면 텍스트가 보입니까? – dokkaebi

+0

첫 번째 "열"에는 ID가 포함되어 있습니다 (그 이유는 내가 보이지 않도록 설정 한 것입니다). – Gonzalo

답변

0

키가 일치하지 않습니다.

VariablesPublicas.ColumnTags의 키는지도에있는 키와 일치해야합니다.

사용 중 하나

map.put("id_obra", servicioweb.getValue(e, "IdObra")); 
map.put("obra", servicioweb.getValue(e, "Obra")); 
... 
VariablesPublicas.ColumnTags = new String[] {"id_obra", "obra"}; 

나 :

map.put("#", servicioweb.getValue(e, "IdObra")); 
map.put("OBRA", servicioweb.getValue(e, "Obra")); 
... 
VariablesPublicas.ColumnTags = new String[] {"#", "OBRA"}; 
+0

완벽한! 그게 해결책이야! 감사!!!!! – Gonzalo

관련 문제