0

Hey guys i am building an app that loads values from json array to listview. What i am having in the database is some stocks, each stocks has 7 prices. I get the data from the json request like this:

Any help will be welcomed and highly appreciated.

I also get the price and the name to be shown on the list and i have already set the in the textviews above so i wanna populate the list view only with values from price1-price7 can i do this??

1 Answer 1

1

Try this code out:

Sending Activity

 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);
        }
    });
}

Receiving activity

HashMap<String, String> hashMap = (HashMap<String, String>) getActivity().getIntent().getSerializableExtra("stockInfo");
Sign up to request clarification or add additional context in comments.

21 Comments

Edited my answer. If there are issues, please post any error logs.
in the putExtra says its not applicable for the arguments(string, List<Map<String, String>>)
how am i going to convert this List<HashMap<String, String>> into a string array???
I think you are going to need a HashMap. You can pull the data you want from the List and get store it in an array. Something like: HashMap<String,String> map = stocksList.get(0); String[] values = new String[map.size()]; Then you can set each item of the array such as values[position] = map.get(KEY value). Alternative is after getting the map ArrayList<String> values = map.values; Then get the array from the arraylist values.toArray();
I updated to code to send a HashMap to your second activity. There you can use the data to set up the listview.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.