2013-04-22 45 views
1

我在android中製作了一些項目並使用SimpleAdapter。我的項目正常工作,但我想用頭來定製我的列表視圖。這裏從我的項目我可以在SimpleAdapter上添加標題嗎?

WatesActivity一些代碼

public class WatesActivity extends ListActivity { 
static final String URL = "http://data.bmkg.go.id/propinsi_15_2.xml"; 
static final String KEY_ITEM = "Cuaca"; 
static final String KEY_ID = "Isi"; 
static final String KEY_ROW = "Row"; 
static final String KEY_KOTA = "Kota"; 
static final String KEY_LINTANG = "Lintang"; 
static final String KEY_BUJUR = "Bujur"; 
static final String KEY_CUACA = "Cuaca"; 
static final String KEY_SUHUMIN = "SuhuMin"; 
static final String KEY_SUHUMAX = "SuhuMax"; 
static final String KEY_KELEMBAPANMIN = "KelembapanMin"; 
static final String KEY_KELEMBAPANMAX = "KelembapanMax"; 
static final String KEY_KECEPATANANGIN = "KecepatanAngin"; 
static final String KEY_ARAHANGIN = "ArahAngin"; 
private ProgressDialog pDialog; 

ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>(); 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.kabupaten); 

    new AmbilData().execute(); 
} 

class AmbilData extends AsyncTask<String, String, String> { 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     pDialog = new ProgressDialog(WatesActivity.this); 
     pDialog.setMessage("Mohon Tunggu Beberapa Saat..."); 
     pDialog.setIndeterminate(false); 
     pDialog.setCancelable(true); 
     pDialog.show(); 
    } 

    @Override 
    protected String doInBackground(String... args) { 
     // TODO Auto-generated method stub 
     XMLParser parser = new XMLParser(); 
     String xml = parser.getXmlFromUrl(URL); 
     Document doc = parser.getDomElement(xml); 

     NodeList row_nodes = doc.getElementsByTagName(KEY_ROW); 
     int row_id = 0; 
     for (int i = row_id; i < row_nodes.getLength();) { 
      // org.w3c.dom.Element row_element = (org.w3c.dom.Element) 
      // row_nodes.item(i); 

      HashMap<String, String> map = new HashMap<String, String>(); 

      Element e = (Element) row_nodes.item(i); 

      map.put(KEY_KOTA, parser.getValue(e, KEY_KOTA)); 
      map.put(KEY_LINTANG, parser.getValue(e, KEY_LINTANG)); 
      map.put(KEY_BUJUR, parser.getValue(e, KEY_BUJUR)); 
      map.put(KEY_CUACA, parser.getValue(e, KEY_CUACA)); 
      map.put(KEY_SUHUMIN, parser.getValue(e, KEY_SUHUMIN)); 
      map.put(KEY_SUHUMAX, parser.getValue(e, KEY_SUHUMAX)); 
      map.put(KEY_KELEMBAPANMIN, 
        parser.getValue(e, KEY_KELEMBAPANMIN)); 
      map.put(KEY_KELEMBAPANMAX, 
        parser.getValue(e, KEY_KELEMBAPANMAX)); 
      map.put(KEY_KECEPATANANGIN, 
        parser.getValue(e, KEY_KECEPATANANGIN)); 
      map.put(KEY_ARAHANGIN, parser.getValue(e, KEY_ARAHANGIN)); 

      menuItems.add(map); 
      break; 
     } 
     return null; 
    } 

    protected void onPostExecute(String file_url) { 
     // TODO Auto-generated method stub 
     pDialog.dismiss(); 
     runOnUiThread(new Runnable() { 

      @Override 
      public void run() { 
       // TODO Auto-generated method stub 
       ListAdapter adapter = new SimpleAdapter(WatesActivity.this, 
         menuItems, R.layout.listkabupaten, new String[] { 
           KEY_KOTA, KEY_CUACA, KEY_LINTANG, 
           KEY_BUJUR, KEY_SUHUMIN, KEY_SUHUMAX, 
           KEY_KELEMBAPANMIN, KEY_KELEMBAPANMAX, 
           KEY_KECEPATANANGIN, KEY_ARAHANGIN }, 
         new int[] { R.id.kota, R.id.cuaca, R.id.lintang, 
           R.id.bujur, R.id.suhumin, R.id.suhumax, 
           R.id.kelembapanmin, R.id.kelembapanmax, 
           R.id.kecepatanangin, R.id.arahangin }); 
       setListAdapter(adapter); 
      } 
     }); 
    } 
} 
} 

kabupaten.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="wrap_content" 
android:orientation="horizontal" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <!-- Kota Label --> 

    <TextView 
     android:id="@+id/kota" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="2dip" 
     android:paddingTop="6dip" 
     android:text="TextView" 
     android:textColor="#43bd00" 
     android:textSize="16sp" 
     android:textStyle="bold" /> 

    <!-- Linear layout for Cuaca --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- Cuaca Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="Cuaca : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/cuaca" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <!-- Linear layout for Lintang --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- Lintang Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="Lintang : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/lintang" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <!-- Linear layout for Bujur --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- Bujur Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="Bujur : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/bujur" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <!-- Linear layout for SuhuMin --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- SuhuMin Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="SuhuMin : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/suhumin" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <!-- Linear layout for SuhuMax --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- SuhuMax Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="SuhuMax : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/suhumax" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <!-- Linear layout for KelembapanMin --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- KelembapanMin Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="KelembapanMin : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/kelembapanmin" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <!-- Linear layout for KelembapanMax --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- KelembapanMax Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="KelembapanMax : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/kelembapanmax" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <!-- Linear layout for Kecepatan Angin --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- Kecepatan Angin Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="Kecepatan Angin : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/kecepatanangin" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <!-- Linear layout for Arah Angin --> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <!-- Arah Angin Label --> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:text="Arah Angin : " 
      android:textColor="#5d5d5d" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/arahangin" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:textColor="#acacac" 
      android:textStyle="bold" /> 
    </LinearLayout> 
</LinearLayout> 

</LinearLayout> 

我想要做的就是添加郵件頭到ListView中,我能做到嗎?

回答

相關問題