I am trying to add values to arraylist in android application.
The problem that I am having is that the value is not being inserted in the array list.
Code Below:
for (var c=0; c < SelectedFavContacts.length; c++){
if (SelectedFavContacts[c] !== undefined) {
var SelectedContact = document.getElementById(SelectedFavContacts[c]).getElementsByTagName('a')[0].innerHTML;
for( i = 0 ; i < arrayKeys.length; i++ )
{
var records = myContacts[arrayKeys[i]];
for(var r_key in records) {
if (SelectedContact == records[r_key].name) {
if (typeof FavContacts[looper] == 'undefined')
{
FavContacts[looper] = new Array();
}
FavContacts[looper].push({"name":records[r_key].name, "pNumber": records[r_key].pNumber, "img": records[r_key].img} );
looper++;
alert(records[r_key].name); //displaying successfully the name successfully;
window.MainActivity.SetFavSettings(records[r_key].name, records[r_key].pNumber, records[r_key].img);
break;
}
}
}
}
}
private List<String> listContactName = new ArrayList<String>();
private List<String> listContactNo = new ArrayList<String>();
private List<String> listFavImg = new ArrayList<String>();
@JavascriptInterface
public void SetFavSettings(String FavContactName, String FavContactNo, String FavImg){
listContactName.add(FavContactName);
listContactNo.add(FavContactNo);
listFavImg.add(FavImg);
DialogInterface.OnClickListener dialogClickListenera = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
finish();
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
}
}
};
// favContactName is being displayed.
//listContactName.get(0) = Nothing
// listContactName.size() = nothing
AlertDialog.Builder buildera = new AlertDialog.Builder(MainActivity.this);
buildera.setMessage("entered " + FavContactName + " checking :)) = " + listContactName.get(0) + " list size = " + listContactName.size()).setPositiveButton("Yes", dialogClickListenera)
.setNegativeButton("No", dialogClickListenera).show();
}
Can you tell me what I am doing wrong please
listContactName.get(0) = Nothing
can happen if parameter you passed is blank..but how canlistContactName.size() = nothing
happen ? It should give you atleast zero. – Ninad Pingale Aug 29 '14 at 13:19