我正在尝试解决我不确定的问题。 I wants to show a parameter call "decription"in the single item's detail when the single listview item is selected but the "decription"should not be displayed on the single listview item.我知道问题出在哪里,但我不确定该如何解决。请给我你的建议!这是我的错误所在的代码:
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.list_item, new String[] { KEY_TITLE, KEY_DESC, KEY_COUNTRY_NAME,
KEY_VENUE_NAME, KEY_START_TIME }, new int[] {
R.id.title,R.id.description, R.id.countryName, R.id.venueName,
R.id.startTime });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String title = ((TextView) view.findViewById(R.id.title))
.getText().toString();
String description = ((TextView) view
.findViewById(R.id.description)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_DESC, description);
startActivity(in);
}
如您所见,KEY_DESC 是我正在谈论的那个,但为了让我使用 in.putextra(KEY_DESC, description);对我来说,可以使用另一个类(class)的 in.getStringExtra。但是描述来自 R.id.description 字段,它在 ListAdapter 中声明,它也显示在 ListView 项目中。我想从 listview items 中删除 description 但仍然可以使用 in.putExtra(KEY_DESC, ??) 方法。我可以知道我该怎么办吗?
最佳答案
如果您不想在主列表中显示描述,只需从 res/layout/list-item.xml 中删除表示描述的 UI 元素(它可能是 TextView with id=@description ).
在那种情况下,您将看不到描述,但仍可通过 SimpleAdapter 访问。
关于java - 如何在单个项目的详细信息中而不是在单个 ListView 项目中显示参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17825259/