我想在外部类方法中访问内部类 Hashmap 变量意味着项目选择的微调器侦听器。我在内部类中声明了 Hashmap,并且在内部类方法中的 Hashmap 中赋值。我正在使用外部类中的 setOnItemSelectedListener 中的键访问哈希图值,但我在哈希图中得到了空值。
我在外部类中设置了静态哈希图,并将值放入内部类中,然后再次从外部类侦听器访问,但再次获得空值。如果有人有其他解决方案,请告诉我。我在这里有点困惑。我不知道我错在哪里。请任何人有解决方案。
以下是外部和内部类
public class ProjectDetailActivity extends SherlockActivity {
// declare hashmap.
HashMap<String, String> phaseIdKv = new HashMap<String, String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
new LoadPhaseData().execute(projId);
//create variable of inner class
final ProjectDetailActivity.LoadPhaseData inner = new ProjectDetailActivity().new LoadPhaseData();
//Listener for Phase spinner
projSpinnerPhase.setOnItemSelectedListener((OnItemSelectedListener) new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
int id = projSpinnerPhase.getSelectedItemPosition();
++id;
String p_id= inner.phaseIdKv.get(id); //Here I want to access inner class hashmap value
Log.v("hashmap value","-"+inner.phaseIdKv.get(id));//getting null
Toast.makeText(getApplicationContext(),"item-"+id+" item2"+item+"p_id"+p_id, Toast.LENGTH_LONG).show();
}
});
}
private class LoadPhaseData extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
-----
JSONArray phaseData = new JSONArray(jsonpPhaseList);
String [] phaseNo = new String[jsonpPhaseList.length()];
String phase;
String phaseId1;
if (phaseData.length() >0) {
for(int i =0;i<phaseData.length();i++){
JSONObject joPhasefromJa = phaseData.getJSONObject(i);
phase = joPhasefromJa.getString("phase_no")
phaseId1 = joPhasefromJa.getString("phase_id");
phaseIdKv.put(phase,phaseId1);
}
}
return null;
}