为什么我无法显示列表视图已被单击?如何使其能够展示?
在我的应用程序中,我使用此代码来显示带有部分的列表视图。 但通过这种方式,我无法获得我要选择的 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);
}
}
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为列表视图定义一个触摸监听器,并且可以显示触摸,例如
添加一个名为 List_onTouch 的触摸监听器
ls2 是您的 listViewObject,如果您单击列表,它会将您的颜色更改为橙色
You can define a touch Listener to your list view and you can show the touch like
add a touch listner named List_onTouch
ls2 is your listViewObject and if you click the list it will change your colour to orange
试试这个
Try this