-4

i'm a beginner to Android development .... can u please tell me if this is this the correct way to declare an hashmap and add it to the arraylist?

Button createagendaButton = (Button) dialog.findViewById(R.id.button2);
createagendaButton.setOnClickListener(new OnClickListener() 
{
@Override
public void onClick(View v) 
{
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("agendaTitle", edit_agendaTitle.getText().toString());
map.put("presenterName", edit_presenterName.getText().toString()); 
mylist.add(map);
}
});
Jaydroid
  • 334
  • 3
  • 13

2 Answers2

1

It seems you are new to android
For starters why dont you go through samples in android sdk

sdk-path/samples/api-version/

and this link

To cheer you up try these that will solve your problems
1. get value from edittext edittext.getText();
2. store values in hashmap as hashmap.put(key,value)
3. instead of going for hashmaps, reconsider the type of data you are storing and try SparseArray if it suits your needs. Sparse arrays are well optimized and good at performance though they are very different in comparison
4. sqlite can store only some types of data. For sqlite on android try this
5. For ensuring proper functioning of your app across devices and resolutions, refer best practices and life cycles of different components used in your app. Also since you are using sqlite, prefer singleton pattern

BlackBeard
  • 145
  • 6
0

The following code will allow you to store the values into the hashmap by using the key => value convention.

Map mMap = new HashMap();
mMap.put("FirstName", firstNameInput.getText().toString());
mMap.put("Surname", surnameInput.getText().toString());
mMap.put("Gender", genderInput.getText().toString());

Note, you will need to change the variable name before .getText() to that of your EditText variable names

http://developer.android.com/reference/java/util/HashMap.html might be of some use!

Smittey
  • 2,475
  • 10
  • 28
  • 35