2012-03-28 60 views
0

某種佈局中奇怪的問題的..我有一個線性佈局像下面具有文本視圖和圖像視圖...我已經寫了線性佈局的單擊事件ID被驗證)我已經得到了一些東西做的...我發現 - 這兩個孩子的意見也正在採取那些點擊事件,並同時在兩個執行結束了......我不能禁用這些焦點或可點擊的事件。 ...(點擊該事件 - 我打電話給一個異步)是否有任何禁用這些意見的焦點...我已經嘗試了大部分像android:focusable和android:clickable ....但它沒有不幫助.. :(佈局及其子

<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(""); 

    }); 
+0

你可以張貼onClickListener代碼.. – user936414 2012-03-28 04:23:00

+0

我有一個片段的onClick轉貼吧..請... – 2012-03-28 05:14:17

+0

的onClick()方法被調用一次。由於textView或imageView沒有問題。 – user936414 2012-03-28 05:28:39

回答

3

只是實施OnclickListener和處理單擊使用有id作爲像下面

 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){ 

    } 

} 

希望它會爲你的作品。

你面對它,因爲@override問題..

+0

你的答案是最有幫助和教育....但我仍想知道爲什麼它會採取兩個click事件(也可能不會發生每次但它確實在某些情況下發生的。) – 2012-03-28 09:04:16