嘿伙计们我正在构建一个将json数组中的值加载到listview的应用程序。我在数据库中拥有的是一些股票,每只股票有7个价格。我从json请求中获取数据:
任何帮助都将受到欢迎并受到高度赞赏。
我也得到了要在列表中显示的价格和名称,我已经在上面的textviews中设置了所以我想只用price1-price7的值来填充列表视图我可以这样做吗?
答案 0 :(得分:1)
尝试使用此代码:
发送活动
public void registerCallClickBack() {
ListView list = (ListView) findViewById(R.id.listView1);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long id) {
TextView tv1 =(TextView)viewClicked.findViewById(R.id.stock_name);
TextView tv2 =(TextView)viewClicked.findViewById(R.id.stock_price);
Intent intent = new Intent(MainActivity.this, StockItem.class);
intent.putExtra("name", tv1.getText().toString());
intent.putExtra("price",tv2.getText().toString());
//passes all you stock info (note you do not need the above 2 lines)
intent.putExtra("stockInfo", stocksList.get(position));
startActivity(intent);
}
});
}
接收活动
HashMap<String, String> hashMap = (HashMap<String, String>) getActivity().getIntent().getSerializableExtra("stockInfo");