Guest User

source code

a guest
Jul 12th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. public class Timeline extends Activity {
  2. //private ProgressBar pb;
  3. private String status;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_timeline);
  9.  
  10. RadioButton rbtnlisting=(RadioButton)findViewById(R.id.rbtnlisting);
  11. RadioButton rbtnclosing=(RadioButton)findViewById(R.id.rbtnclosing);
  12. RadioButton rbtnprospek=(RadioButton)findViewById(R.id.rbtnprospek);
  13. final EditText edtstatus=(EditText)findViewById(R.id.edtstatus);
  14. Button btnpost=(Button)findViewById(R.id.btnpost);
  15.  
  16. edtstatus.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
  17. btnpost.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
  18. rbtnlisting.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
  19. rbtnclosing.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
  20. rbtnprospek.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
  21.  
  22. btnpost.setOnClickListener(new OnClickListener() {
  23.  
  24. @Override
  25. public void onClick(View v) {
  26. if (edtstatus.getText().length()>5) {
  27. //pb.setVisibility(View.VISIBLE);
  28. new MyAsyncTask().execute("ccc");
  29. }else {
  30. Toast.makeText(getBaseContext(), "Your status is too short", Toast.LENGTH_LONG).show();
  31. }
  32. }
  33. });
  34. }
  35.  
  36. private class MyAsyncTask extends AsyncTask<String, Integer, Double>{
  37.  
  38. @Override
  39. //protected Double doInBackground(String... params) {
  40. protected Double doInBackground(String... params) {
  41. // TODO Auto-generated method stub
  42. postData(params[0]);
  43. return null;
  44. }
  45.  
  46. protected void onPostExecute(Double result){
  47. //pb.setVisibility(View.GONE);
  48. Toast.makeText(getApplicationContext(), "Code Sent", Toast.LENGTH_LONG).show();
  49. }
  50. protected void onProgressUpdate(Integer... progress){
  51. //pb.setProgress(progress[0]);
  52. }
  53.  
  54. public void postData(String id) {
  55. // Create a new HttpClient and Post Header
  56. EditText edtstatus=(EditText)findViewById(R.id.edtstatus);
  57. RadioButton rbtnlisting=(RadioButton)findViewById(R.id.rbtnlisting);
  58. RadioButton rbtnclosing=(RadioButton)findViewById(R.id.rbtnclosing);
  59. RadioButton rbtnprospek=(RadioButton)findViewById(R.id.rbtnprospek);
  60.  
  61. if (rbtnclosing.isSelected()) {status="Closing";}
  62. else if (rbtnprospek.isSelected()) {status="Prospek";}
  63. else if (rbtnlisting.isSelected()) {status="Listing";}
  64.  
  65. HttpClient httpclient = new DefaultHttpClient();
  66. HttpPost httppost = new HttpPost("http://xxx.xxx.xxx.xxx/dummy/insert.php");
  67. try {
  68. // Add your data
  69. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  70. nameValuePairs.add(new BasicNameValuePair("idsales",OtherClass.getIdSales().toString()));
  71. nameValuePairs.add(new BasicNameValuePair("jenis", status));
  72. nameValuePairs.add(new BasicNameValuePair("remark", edtstatus.getText().toString()));
  73. nameValuePairs.add(new BasicNameValuePair("path", "coba coba"));
  74. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  75.  
  76. // Execute HTTP Post Request
  77. HttpResponse response = httpclient.execute(httppost);
  78. Toast.makeText(getBaseContext(), "Successfully posting status", Toast.LENGTH_LONG).show();
  79.  
  80. }
  81. catch (ClientProtocolException e)
  82. {
  83. // TODO Auto-generated catch block
  84. } catch (IOException e)
  85. {
  86. // TODO Auto-generated catch block
  87. }
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment