Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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) {
						// TODO Auto-generated method stub
						Toast.makeText(getActivity(),
								strDates[Dates],
								Toast.LENGTH_SHORT).show();

					}
				});
		//objBuilder.setView(v);
		AlertDialog objAlert = objBuilder.create();
		objAlert.show();

CODE FOR GETTING ARRAYLIST
C#
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);
				//objLinksData.put("linkURL", String.valueOf(i));
				//objLinksData.put("linkName", e.getString("linkName"));
				objEventsData.put("eventID", e.getString("eventID"));
				objEventsData.put("eventPreviousID", e.getString("eventPreviousID"));
				objEventsData.put("eventDate", e.getString("eventDate"));
				//objLinksData.put("linkID", e.getString("linkID"));
				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 {
			// Create a URL for the desired page
			URL url = new URL(" ") ;

			// Read all the text returned by the server
			BufferedReader in = new BufferedReader(new InputStreamReader(
					url.openStream()));
			String str;
			StringBuilder sb = new StringBuilder(100);
			while ((str = in.readLine()) != null) {
				sb.append(str);
				// str is one line of text; readLine() strips the newline
				// character(s)
			}
			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;
			}
		}
	}

}
Posted
Updated 4-Sep-12 20:07pm
v3
Comments
lewax00 4-Sep-12 11:47am    
It's impossible to know without seeing the code you're using to create the dialog...
ridoy 4-Sep-12 12:14pm    
need to see your code..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900