0

i am trying to listen to click on listview which each row is hashmap:

lvItem = (ListView)getView().findViewById(R.id.listWork); 
ArrayList<HashMap<String, String>> mylistData = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>(); 
int[] columnID = new int[] {R.id.tvPK, R.id.tvText }; 
map.put("PK", "1"); 
map.put("ITEM", "2"); 
mylistData.add(map);

SimpleAdapter arrayadapter = new SimpleAdapter(getActivity(), mylistData, R.layout.row_hidden_id, new String[] {"PK", "ITEM"}, columnID);
lvItem.setAdapter(arrayadapter);
lvItem.setTextFilterEnabled(true);

lvItem.setOnItemClickListener(new OnItemClickListener() {  
 @Override  
 public void onItemClick(AdapterView<?> a, View v, int p, long id) {   
  Object o = lvItem.getItemAtPosition(p);   
  ErrorMsg("ID:" + o.toString());
 } });

i am getting something like "{ITEX=2, PK=1}"
i need to cast the object (o) as hashmap and get only the pk...

any idea?

Thanks!

3
  • I don't get what you're trying to do. The mylistData list is never added to anything (not in the code you've pasted anyways). So you're basically filling the list with some data and then? Commented Jun 26, 2013 at 14:42
  • I think you're using an ArrayAdapter and filling it with a single HashMap. This is probably not what you want. Consider extending BaseAdapter and using that to manipulate whatever objects you like. Commented Jun 26, 2013 at 14:50
  • edited - forgot 3 lines.. sorry. Commented Jun 26, 2013 at 14:56

1 Answer 1

1

Try:

lvItem.setOnItemClickListener(new OnItemClickListener() {  
    @Override  
    public void onItemClick(AdapterView<?> a, View v, int p, long id) {   
        HashMap<String,String> map = (HashMap) lvItem.getItemAtPosition(p);   
        ErrorMsg("ID:" + map.get("PK"));
     } 
});
Sign up to request clarification or add additional context in comments.

Comments

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.