Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Timeline extends Activity {
- //private ProgressBar pb;
- private String status;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_timeline);
- RadioButton rbtnlisting=(RadioButton)findViewById(R.id.rbtnlisting);
- RadioButton rbtnclosing=(RadioButton)findViewById(R.id.rbtnclosing);
- RadioButton rbtnprospek=(RadioButton)findViewById(R.id.rbtnprospek);
- final EditText edtstatus=(EditText)findViewById(R.id.edtstatus);
- Button btnpost=(Button)findViewById(R.id.btnpost);
- edtstatus.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
- btnpost.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
- rbtnlisting.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
- rbtnclosing.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
- rbtnprospek.setTextSize(TypedValue.COMPLEX_UNIT_PX, getBaseContext().getResources().getDimensionPixelSize( R.dimen.lbltitlelistviewitem));
- btnpost.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (edtstatus.getText().length()>5) {
- //pb.setVisibility(View.VISIBLE);
- new MyAsyncTask().execute("ccc");
- }else {
- Toast.makeText(getBaseContext(), "Your status is too short", Toast.LENGTH_LONG).show();
- }
- }
- });
- }
- private class MyAsyncTask extends AsyncTask<String, Integer, Double>{
- @Override
- //protected Double doInBackground(String... params) {
- protected Double doInBackground(String... params) {
- // TODO Auto-generated method stub
- postData(params[0]);
- return null;
- }
- protected void onPostExecute(Double result){
- //pb.setVisibility(View.GONE);
- Toast.makeText(getApplicationContext(), "Code Sent", Toast.LENGTH_LONG).show();
- }
- protected void onProgressUpdate(Integer... progress){
- //pb.setProgress(progress[0]);
- }
- public void postData(String id) {
- // Create a new HttpClient and Post Header
- EditText edtstatus=(EditText)findViewById(R.id.edtstatus);
- RadioButton rbtnlisting=(RadioButton)findViewById(R.id.rbtnlisting);
- RadioButton rbtnclosing=(RadioButton)findViewById(R.id.rbtnclosing);
- RadioButton rbtnprospek=(RadioButton)findViewById(R.id.rbtnprospek);
- if (rbtnclosing.isSelected()) {status="Closing";}
- else if (rbtnprospek.isSelected()) {status="Prospek";}
- else if (rbtnlisting.isSelected()) {status="Listing";}
- HttpClient httpclient = new DefaultHttpClient();
- HttpPost httppost = new HttpPost("http://xxx.xxx.xxx.xxx/dummy/insert.php");
- try {
- // Add your data
- List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
- nameValuePairs.add(new BasicNameValuePair("idsales",OtherClass.getIdSales().toString()));
- nameValuePairs.add(new BasicNameValuePair("jenis", status));
- nameValuePairs.add(new BasicNameValuePair("remark", edtstatus.getText().toString()));
- nameValuePairs.add(new BasicNameValuePair("path", "coba coba"));
- httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
- // Execute HTTP Post Request
- HttpResponse response = httpclient.execute(httppost);
- Toast.makeText(getBaseContext(), "Successfully posting status", Toast.LENGTH_LONG).show();
- }
- catch (ClientProtocolException e)
- {
- // TODO Auto-generated catch block
- } catch (IOException e)
- {
- // TODO Auto-generated catch block
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment