@SuppressLint("NewApi") public void appendMessageData(final JSONObject message) { final JSONObject m_message = message; final LinearLayout list = (LinearLayout) findViewById(R.id.linearlayout_main); SwipeLayout newCell_host = (SwipeLayout) (View.inflate(this, R.layout.cell_message, null)); // set show mode. newCell_host.setShowMode(SwipeLayout.ShowMode.PullOut); // add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary) newCell_host.setDragEdge(DragEdge.Right); newCell_host.setBottom(R.id.right_wrapper); ImageView img_delete = (ImageView) newCell_host.findViewById(R.id.imageView_delete); img_delete.setImageResource(R.drawable.remove); img_delete.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub progressView.setVisibility(View.VISIBLE); disableButtons(); String msg_id; try { msg_id = message.getString("msg_id"); new RemoveMessage(msg_id).execute(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); TextView message_title = (TextView) newCell_host.findViewById(R.id.textView_message_title); TextView message_subtitle = (TextView) newCell_host.findViewById(R.id.textView_message_sub_title); ImageView messageButton = (ImageView) newCell_host.findViewById(R.id.message_Button); messageButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { int action_code = m_message.getInt("action_code"); String action_data = m_message.getString("action_data"); String message_id = m_message.getString("msg_id"); switch (action_code) { case 3: progressView.setVisibility(View.VISIBLE); disableButtons(); AcceptInvite acceptInvite = new AcceptInvite(message_id, action_data); acceptInvite.execute(); break; case 4: progressView.setVisibility(View.VISIBLE); disableButtons(); GetConf getConf = new GetConf(action_data); getConf.execute(); break; default: break; } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); TextView messageButtonNote = (TextView) newCell_host.findViewById(R.id.message_Button_Note); try { message_title.setText(message.getString("title")); message_subtitle.setText(message.getString("subtitle")); int action_code = message.getInt("action_code"); switch (action_code) { case 1: messageButton.setVisibility(View.INVISIBLE); messageButtonNote.setVisibility(View.INVISIBLE); break; case 2: messageButton.setImageResource(R.drawable.add_host); messageButtonNote.setText("已加入"); messageButtonNote.setTextColor(R.color.green_overlay); break; case 3: messageButton.setImageResource(R.drawable.join); messageButtonNote.setText(R.string.str_join_in); messageButtonNote.setTextColor(R.color.green); break; case 4: messageButton.setImageResource(R.drawable.right); messageButtonNote.setText("查看"); messageButtonNote.setTextColor(R.color.grey); break; default: break; } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } newCell_host.setTag(0); registerForContextMenu(newCell_host); list.addView(newCell_host); }