【发布时间】:2012-03-28 14:58:26
【问题描述】:
布局中存在某种奇怪的问题。我有一个像下面这样的线性布局,它有文本视图和图像视图...我已经为线性布局编写了一个点击事件——比如点击那个线性布局(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("");
});
【问题讨论】:
-
你能把onClickListener的代码贴出来吗..
-
我已经用 onClick sn-p 转发了它。请检查...
-
onClick() 方法只被调用一次。因为textView或者imageView没有问题。
-
不,不.. 如果内部的 imageview 与该布局一起被触摸,onClick 会被调用两次.. 不知道为什么...一旦点击,我就放置了一些“忙碌”变量,并在发布后使其为 false执行是为了避免这两个事件......有什么可以避免这些可聚焦性..
-
表示当我们点击 imageview 和 textview 部分时你不想采取行动,对吧?
标签: android