i have developed an application where i need to show an alert dialog box with list of item,though i have filtered the duplicate data but it is still repeating the items...i really don't have any idea why it is happening...can anybody please help!!
CODE FOR CREATING DIALOG BOX
final CharSequence[] strDates = objEventDataLoader.arrDatesString.toArray(new CharSequence[objEventDataLoader.arrDatesString.size()]);
AlertDialog.Builder objBuilder = new AlertDialog.Builder(this.getActivity());
objBuilder.setTitle("Pick Date");
objBuilder.setItems(strDates,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int Dates) {
Toast.makeText(getActivity(),
strDates[Dates],
Toast.LENGTH_SHORT).show();
}
});
AlertDialog objAlert = objBuilder.create();
objAlert.show();
CODE FOR GETTING ARRAYLIST
public class EventDataLoader {
private static String strJSON;
private JSONArray arrJSONEventsData;
public ArrayList<hashmap><string,>> arrEventList = new ArrayList<hashmap><string,>>();
public ArrayList<string> arrDatesString = new ArrayList<string>();
public EventDataLoader() {
readTextFromSource();
}
private void onDataLoaded() {
try {
arrJSONEventsData = new JSONArray(strJSON);
int strCount = arrJSONEventsData.length();
for (int i = 0; i < strCount; i++) {
HashMap<string,> objEventsData = new HashMap<string,>();
JSONObject e = arrJSONEventsData.getJSONObject(i);
objEventsData.put("eventID", e.getString("eventID"));
objEventsData.put("eventPreviousID", e.getString("eventPreviousID"));
objEventsData.put("eventDate", e.getString("eventDate"));
arrEventList.add(objEventsData);
arrDatesString.add(e.getString("eventDate"));
}
checkDataDuplicacy();
}
catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
}
private void readTextFromSource() {
try {
URL url = new URL(" ") ;
BufferedReader in = new BufferedReader(new InputStreamReader(
url.openStream()));
String str;
StringBuilder sb = new StringBuilder(100);
while ((str = in.readLine()) != null) {
sb.append(str);
}
in.close();
strJSON = sb.toString();
onDataLoaded();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
}
private void checkDataDuplicacy()
{
for (int i = 0; i < arrEventList.size(); i++)
{
removeIfDuplicateAvailable(i);
}
}
private void removeIfDuplicateAvailable(int nCount)
{
HashMap<string,> objEventsData = arrEventList.get(nCount);
String strPrvsId = objEventsData.get("eventPreviousID");
if(strPrvsId.equalsIgnoreCase("-1"))
{
}
else
{
removeEventObjectWithPrvsId(strPrvsId);
}
}
private void removeEventObjectWithPrvsId(String strPrvsId)
{
for (int i = 0; i < arrEventList.size(); i++)
{
HashMap<string,> objEventsData = arrEventList.get(i);
if(strPrvsId.equalsIgnoreCase(objEventsData.get("eventID")))
{
Log.i("development","Finally Removing");
arrEventList.remove(i);
arrDatesString.remove(i);
Log.i("development",arrDatesString.get(i));
return;
}
}
}
}