ListView的添加headView以及制定item等相关操作

如果你想scroll down to list's 10 item  你需要yourListView.setSelection(position)

如果你想创建一个这样的vlayout

Section '1' is linear layout 包含imageview and textview

Section '2' is listview包含特定的customze items list

而你又希望你的scrollbar 可以同时对上面两个起作用

那么你需要

View headerView = getLayoutInflater().inflate( 
        R
.layout.foo_list_header, null); 
 
mListView
= (ListView) findViewById(...); 
mListView
.addHeaderView(headerView); 
 
setListAdapter
(...); 

去掉横线

getListView().setDivider(null); 
getListView
().setDividerHeight(0); 

Or in XML:

  android:divider="@drawable/list_item_divider" 
        android
:dividerHeight="1dp"
 
3更换背景颜色

不用 View.setBackgroundColor() 而用View.setBackgroundDrawable() or View.setBackgroundResource

 

4.相关事件

listView.setOnItemClickListener(new OnItemClickListener() { 
   
public void onItemClick(AdapterView<?> adapter, View view, int which, long id) { 
       
String sUrl = "myUrl"; 
        URL url
= new URL(sUrl); 
 
       
URLConnection conn = url.openConnection(); 
        conn
.setDoOutput(true); 
 
       
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charset.forName("ISO-8859-1"))); 
 
       
String res = ""; 
 
       
String line; 
       
while ((line = rd.readLine()) != null) { 
            res
+= line; 
       
} 
 
        rd
.close(); 
   
} 
}); 

你可能感兴趣的:(android,xml)