Monday, 24 October 2016

Add Event Handler for Button Click in Android

Hi Just see one function where you can find how to add an event handler

package com.finder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Bookings  extends Activity{
EditText ename,ecrd1,etime;
TextView tname,tcrd,ttime;
Button ok,view;
public static String name;
public static String crd;
public static String time;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.booking);
        ename=(EditText)findViewById(R.id.etname);
        ecrd1=(EditText)findViewById(R.id.etcrd);
        etime=(EditText)findViewById(R.id.ettime);
        tname=(TextView)findViewById(R.id.tvname);
        tcrd=(TextView)findViewById(R.id.tvcrd);
        tname=(TextView)findViewById(R.id.tvname);
        ttime=(TextView)findViewById(R.id.tvtime);
        ok=(Button)findViewById(R.id.btok);
        view=(Button)findViewById(R.id.btview);
        ok.setOnClickListener(new OnClickListener() {
                        @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                   name=ename.getText().toString();
                   crd=ecrd.getText().toString();
                   time=etime.getText().toString();
               
        
                    }
               
           
               


        });
      
       
    }
   

}








No comments:

Post a Comment