Reputation: 23596
In my application, I am using this code to show the List View with Section. But with this way I am not able to get that which listItem I am going to select. I mean I am not able to see the chang colour while I am going to press on any list item. So how to make it possible for this code:
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);
}
}
Upvotes: 0
Views: 113
Reputation: 527
You can define a touch Listener to your list view and you can show the touch like
ListView.setOnTouchListener(List_onTouch);
add a touch listner named 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 is your listViewObject and if you click the list it will change your colour to orange
Upvotes: 1
Reputation: 11230
Try this
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
Upvotes: 1