我在这里有一个代码,我想通过单击保存按钮来传递哈希映射函数。我看了Here,但找不到解决方案。如何从意图传递HashMap <String,List <String>>
上点击按钮,我需要通过hasmap.Anyone请帮助this.My代码是:
btnsave = (Button) findViewById(R.id.btn_save);
btnsave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
expandableDataPump.getData();
Intent intent = new Intent(getApplicationContext(), ExpandableList.class);
//HERE I NEED TO PASS HASHMAP
intent.putStringArrayListExtra("details",(HashMap<String,>) expandableDataPump.getData());
startActivity(intent);
} catch (Exception ex) {
ex.printStackTrace();
Toast.makeText(MainActivity.this, "You have an ERROR", Toast.LENGTH_LONG).show();
}
}
});
}
public class ExpandableDataPump {
public HashMap<String, List<String>> getData() {
HashMap<String, List<String>> expandableListDetail = new HashMap<>();
for (int i = 2; i < container.getChildCount(); i++) {
if (container.getChildAt(i) instanceof RelativeLayout) {
List<String> childs = new ArrayList<>();
childs.add(((TextView)container.getChildAt(i).findViewById(R.id.textout)).getText().toString());
expandableListDetail.put(txtHeading.getText().toString(), childs);
}
}
return expandableListDetail;
}
}
}
你有什么问题?你得到任何异常/崩溃? –
虽然编写代码的意图红线出现,我不能运行它.. –