我想从listviews显示详细数据android,我做到了......但问题是,我不知道如何通过单击下一个/上一个按钮来显示下一个/上一个详细数据的功能在listview数据上。
这是我的第一个活动
String[] values = new String[] { "Android Example ListActivity", "Adapter implementation", "Simple List View With ListActivity",
"ListActivity Android", "Android Example", "ListActivity Source Code", "ListView ListActivity Array Adapter", "Android Example ListActivity" };
// Binding Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, values));
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// selected item
String product = ((TextView) view).getText().toString();
// Launching new Activity on selecting single List Item
Intent intent = new Intent(getApplicationContext(), SingleListItem.class);
// sending data to new activity
intent .putExtra("product", product);
intent.putExtra("pos",position);
startActivity(intent);
}
});
}
}
这是我的第二个活动,我有详细信息,我想在这两个按钮中放下两个按钮,我想要处理我的列表视图数据
TextView txtProduct = (TextView) findViewById(R.id.product_label);
Intent intent = getIntent();
// getting attached intent data
String product = getIntent().getStringExtra("product");
int position=getIntent().getIntExtra("pos", 1);
// displaying selected product name
txtProduct.setText(" \n"+position+" \n" +product);
}
答案 0 :(得分:0)
//try this way
String[] values = new String[] { "Android Example ListActivity", "Adapter implementation", "Simple List View With ListActivity",
"ListActivity Android", "Android Example", "ListActivity Source Code", "ListView ListActivity Array Adapter", "Android Example ListActivity" };
// Binding Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, values));
ListView lv = getListView();
// listening to single list item on click
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// selected item
String product = ((TextView) view).getText().toString();
// Launching new Activity on selecting single List Item
Intent intent = new Intent(getApplicationContext(), SingleListItem.class);
// sending data to new activity
intent.putExtra("products", values);
intent.putExtra("pos",position);
startActivity(intent);
}
});
Intent intent = getIntent();
// getting attached intent data
String[] product = getIntent().getStringArrayExtra("product");
int position=getIntent().getIntExtra("pos", 1);