布局中有一些奇怪的问题..我有一个像下面的线性布局,它有文本视图和图像视图...我已经为线性布局写了一个点击事件 - 就像点击那个linearlayout(id是验证)我有一些事情要做......我发现 - 那两个孩子的观点也在接受这些点击事件并最终同时进行两次执行......我无法禁用那些焦点或可点击的事件....(点击该事件 - 我正在调用异步)是否有任何禁用这些视图从焦点...我已经尝试了大多数像android:focusable和android:可点击....但它没有帮助.. :(
<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 :(得分: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 ..
,您面临的问题