我在這裏有一個代碼,我想通過單擊保存按鈕來傳遞哈希映射函數。我看了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;
}
}
}
你有什麼問題?你得到任何異常/崩潰? –
雖然編寫代碼的意圖紅線出現,我不能運行它.. –