0

some kind of weird problem in layouts.. I have a linear layout like below which has text view and image view... i have written a click event for linear layout - like on click of that linearlayout (id is verify) i have got some stuffs to do... i have found that -- those two child views are also taking those click events and ending up in two execution simultaneously... i could not disable those focus or clickable events.... ( on click of that event - i am calling an async ) is there any to disable those views from taking focus... i have tried most of it like android:focusable and android:clickable.... but it did not help.. :(

<LinearLayout
        android:id="@+id/verify"
        android:layout_width="150dp"
        android:layout_height="100dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/clearbluesky"

        android:orientation="vertical"
        >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:focusable="false"
            android:text="Verify"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="70dp"
            android:layout_height="30dp"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:clickable="false"
            android:focusable="false"
            android:src="@drawable/fps" />
    </LinearLayout>

continue.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
                        new AsyncTask<String, String, String>()
                        {
                            boolean testresult = false;
                            boolean clearBuf = false;
                            ProgressDialog progressDialog = null;
                            @Override
                            protected void onPostExecute(String result){                                                                    super.onPostExecute(result);
                                progressDialog.dismiss();
                            }
                            @Override
                            protected void onPreExecute() {

                                super.onPreExecute();
                                progressDialog = new ProgressDialog(getApplicationContext());
                                progressDialog.setMessage("Continue");
                                progressDialog.setIndeterminate(false);
                                progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                                progressDialog.show();
                            }
                            @Override
                            protected String doInBackground(String... params) {
                                                    //   Calling some function              
                                return null;
                            }

                        }.execute("");

    });
Sanjay Herle
  • 313
  • 2
  • 4
  • 15

1 Answers1

3

Simply Implemented OnclickListener and handle click using there id as like below

     tv = (TextView) findViewById(R.id.textView1);
     im = (ImageView) findViewById(R.id.imageView2);
     ly = (LinearLayout) findViewById(R.id.verify);
     ly.setOnClickListener(this);
     tv.setOnClickListener(this);
     im.setOnClickListener(this);


    @Override
public void onClick(View v) {
    if(v==ly){
        Toast.makeText(TestActivity.this, "I clicked",
                Toast.LENGTH_SHORT).show();

    }if(v==tv){

    }if(v==im){

    }

}

Hope it will works for you.

The problem you are facing its because of @override..

Community
  • 1
  • 1
RobinHood
  • 10,897
  • 4
  • 48
  • 97
  • your answer was most helpful and educative.... but still i am wondering why would it take two click events ( it may not happen everytime but it does happen in some cases..) – Sanjay Herle Mar 28 '12 at 09:04