在我的应用程序中,我使用此代码显示带有Section的列表视图。 但是通过这种方式,我无法获得我将要选择的listItem。我的意思是,当我要按任何列表项时,我无法看到变色。那么如何使这段代码成为可能:
public static ProgressDialog m_progressDialog;
public Map<String,?> createItem(String title, String caption) {
Map<String,String> item = new HashMap<String,String>();
item.put(ITEM_TITLE, title);
item.put(ITEM_CAPTION, caption);
return item;
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
// create our list and custom adapter
SeparatedListAdapter adapter = new SeparatedListAdapter(this);
adapter.addSection("Local documents:", new ArrayAdapter<String>(this,
R.layout.list_item, new String[] { "WindowsONE Mobile PK", "WindowsorONE Moldings","Filet for a burger video" }));
adapter.addSection("Non-local resources:", new ArrayAdapter<String>(this,
R.layout.list_item, new String[] { "Launch Photo slideshow link", "Dealer locator link" }));
adapter.addSection("Send emails:", new ArrayAdapter<String>(this,
R.layout.list_item, new String[] { "Send Dealer Locator email", "Send Catalog email","Send install instrucation link" }));
//For extra Information in Listview
//adapter.addSection("Non-local resources:", new SimpleAdapter(this, security, R.layout.list_complex,
//new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));
ListView list = getListView();
list.setAdapter(adapter);
list.setTextFilterEnabled(true);
list.setOnItemClickListener(this);
}
}
答案 0 :(得分:1)
试试这个
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
答案 1 :(得分:1)
您可以为列表视图定义触控侦听器,并可以显示触控
ListView.setOnTouchListener(List_onTouch);
添加名为List_onTouch的触摸列表器
OnTouchListener List_onTouch=new OnTouchListener(){
@Override
public boolean onTouch(View arg0,MotionEvent arg1){
int iAction=arg1.getAction();
if(iAction==0){
ls2.setBackgroundcolor(Color.white);
}
else{
ls2.setBackgroundcolor(Color.orange);
}
return false;
}
};
ls2是你的listViewObject,如果点击列表,它会将你的颜色改为橙色