对ArrayList进行排序<hashmap <string,string =“”>&gt;按日期范围</hashmap <string,>

时间:2012-05-04 22:19:12

标签: android json listactivity sorting

我正在开发一个活动应用,需要能够在发生的月份之前整理我的活动。我打算使用“菜单”按钮显示可供选择的月份列表。我尝试使用Collections.sort但Eclipse不允许使用HashMap String,String。我怎样才能让这堂课只在七月举办活动?

公共类Schedule扩展了ListActivity {

protected EditText searchText;
protected SQLiteDatabase db;
protected Cursor cursor;
protected TextView textView;
protected ImageView imageView;
protected ArrayList<HashMap<String, String>> myList;
protected ImageLoader imageLoader;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.schedule);

    View layout = findViewById(R.id.gradiant);

    GradientDrawable gd = new GradientDrawable(
            GradientDrawable.Orientation.TOP_BOTTOM, new int[] {
                    0xFF95B9C7, 0xFF06357A });
    gd.setCornerRadius(2f);

    layout.setBackgroundDrawable(gd);

    new GetEventsTask().execute("word");

}

public void featured(View view) {
    startActivity(new Intent(getApplicationContext(), Featured.class));
}

public void schedule(View view) {

}

public void venue(View view) {
    startActivity(new Intent(getApplicationContext(), Venues.class));
}

public void share(View view) {
    startActivity(new Intent(getApplicationContext(), Friends.class));
}

public void myravinia(View view) {
    startActivity(new Intent(getApplicationContext(), Account.class));
}

protected class GetEventsTask extends
        AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {

    protected ArrayList<HashMap<String, String>> threadList;

    private final ProgressDialog dialog = new ProgressDialog(Schedule.this);

    protected void onPreExecute() {
        this.dialog.setMessage("Loading...");
        this.dialog.setCancelable(false);
        this.dialog.show();
    }



    @Override
    protected ArrayList<HashMap<String, String>> doInBackground(
            String... params) {

        Log.v("Yup", "The thread is running");
        threadList = new ArrayList<HashMap<String, String>>();

        JSONObject json = JSONfunctions
                .getJSONfromURL("my.jason.feed.url");

        try {


            JSONArray current = json.getJSONArray("d");

            for (int i = 0; i < current.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject e = current.getJSONObject(i);

                map.put("id", String.valueOf(i));
                map.put("showid", "" + Html.fromHtml(e.getString("ShowID")));
                map.put("name", "" + Html.fromHtml(e.getString("Title")));
                map.put("showvenue", "" + e.getString("ShowVenue"));
                map.put("subtitle",
                        "" + Html.fromHtml(e.getString("SubTitle")));
                map.put("venueid", "" + e.getString("VenueID"));

                String showDate = e.getString("ShowDate");
                long epoch = Long.parseLong(showDate);
                Date showDatePresent = new Date(epoch * 1000);
                SimpleDateFormat sdf = new SimpleDateFormat("E, MMMM d");
                String dateOfShow = sdf.format(showDatePresent);
                map.put("showdate", "" + dateOfShow);

                String showStart = e.getString("ShowStart");
                long epoch2 = Long.parseLong(showStart);
                Date showTimePresent = new Date(epoch2 * 1000);
                SimpleDateFormat sdf2 = new SimpleDateFormat("h:mm a");
                String timeOfShow = sdf2.format(showTimePresent);
                map.put("showstart", "" + timeOfShow);

                String showEnd = e.getString("ShowEnd");
                long epoch3 = Long.parseLong(showEnd);
                Date showEndPresent = new Date(epoch3 * 1000);
                SimpleDateFormat sdf3 = new SimpleDateFormat("h:mm a");
                String endOfShow = sdf3.format(showEndPresent);
                map.put("showend", "" + endOfShow);

                String gatesOpen = e.getString("GatesOpen");
                long epoch4 = Long.parseLong(gatesOpen);
                Date gatesOpenPresent = new Date(epoch4 * 1000);
                SimpleDateFormat sdf4 = new SimpleDateFormat(
                        "'Gates open: 'h:mm a");
                String gatesAreOpen = sdf4.format(gatesOpenPresent);
                map.put("gatesopen", "" + gatesAreOpen);

                map.put("aboutartist", "" + e.getString("AboutArtist"));
                map.put("program",
                        "" + Html.fromHtml(e.getString("Program")));
                map.put("programnotes",
                        "" + Html.fromHtml(e.getString("ProgramNotes")));
                map.put("pricing",
                        "" + Html.fromHtml(e.getString("Pricing")));
                map.put("featuring", "" + e.getString("Featuring"));
                map.put("parkdetails", "" + e.getString("ParkDetails"));
                map.put("starred", "" + e.getString("Starred"));

                map.put("image500", "" + e.getString("Image500"));

                map.put("image250", "" + e.getString("Image250"));

                map.put("aboutartist",
                        "" + Html.fromHtml(e.getString("AboutArtist")));
                threadList.add(map);
            }

        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());

        }

        return threadList;          
    }


    protected void onPostExecute(ArrayList<HashMap<String, String>> result) {

        myList = new ArrayList<HashMap<String, String>>();
        myList = result;

        LazyAdapter adapter = new LazyAdapter(Schedule.this, myList);
        setListAdapter(adapter);

        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                HashMap<String, String> hashMap = myList.get(position);
                // hashMap.put("map", hashMap);
                Intent intent = new Intent(getApplicationContext(),
                        ArtistDetails.class);
                intent.putExtra("map", hashMap);

                startActivity(intent);                  
            }

        });

        if (this.dialog.isShowing()) {
            this.dialog.dismiss();
        }
    }

}

}

我知道我将代码留在那里以获得对此任务不重要的功能,但努力做到详细... 如果我有任何其他细节可以帮助我解决这个问题,请告诉我。干杯!

我的2个适配器:

public class LazyAdapter extends BaseAdapter {

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());

}

public int getCount() {
    return data.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.line_item, null);

    TextView name = (TextView)vi.findViewById(R.id.title); // title
    TextView showdate = (TextView)vi.findViewById(R.id.showdate); // showdate
    TextView showstart = (TextView)vi.findViewById(R.id.showstart); // showstart
    TextView showvenue = (TextView)vi.findViewById(R.id.showvenue); // showstart
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image


    // Setting all values in listview
    name.setText(data.get(position).get("name"));
    showdate.setText(data.get(position).get("showdate"));
    showstart.setText(data.get(position).get("showstart"));
    showvenue.setText(data.get(position).get("showvenue"));
    imageLoader.DisplayImage(data.get(position).get("image250"), thumb_image);
    return vi;
}

}

public class JSONfunctions {

public static JSONObject getJSONfromURL(String url){
    InputStream is = null;
    String result = "";
    JSONObject jArray = null;

    //http post
    try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(url);
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

    }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
    }

  //convert response to string
    try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();
    }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
    }

    try{

        jArray = new JSONObject(result);            
    }catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
    }

    return jArray;
}

}

0 个答案:

没有答案