Android ImageButton事件侦听器赢了';t在ScrollView内工作->;视图
Android ImageButton事件侦听器赢了';t在ScrollView内工作->;视图,android,Android,ImageButton事件侦听器不工作 以下是我的代码(已更新): XML: 此代码不起作用。谢谢您的帮助。试试这个:----- 这在矿井侧运行良好: setContentView(R.layout.vhscroll) ImageButton ImageButton=(ImageButton)findViewById(R.id.imagebutton1) xml代码是: <LinearLayout xmlns:android="http://schemas.android.com
ImageButton
事件侦听器不工作
以下是我的代码(已更新):
XML:
此代码不起作用。谢谢您的帮助。试试这个:-----
这在矿井侧运行良好: setContentView(R.layout.vhscroll) ImageButton ImageButton=(ImageButton)findViewById(R.id.imagebutton1) xml代码是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView android:id="@+id/scrollview" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="@+id/imagebutton1" android:layout_width="100dip" android:layout_height="100dip" android:src="@drawable/sample_0" android:scaleType="fitXY"/>
</.......>
发布您的整个活动代码。其他代码只是声明和初始化。根据用户Uttam Suggested initialize ImageButton和get view然后declare onClick(),因此请尝试他的代码。感谢回复Uttam。伙计们,我上面的代码还是一样的。它不起作用。。。我已经初始化了我的按钮,但是我没有在上面显示它。这段代码不起作用。请帮帮我…伙计们,我的代码正在运行。苏丽,这是个打字错误。。。谢谢你的回复。
public class Main extends Activity{
ImageButton imgBtn1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgBtn1 = (ImageButton) findViewById(R.id.img_btn1);
imgBtn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.w("onClick", "ImageButton Clicked");
}
});
}
}
ImageButton imgBtn1 = (ImageButton)findViewById(R.id.img_btn1);
imgButn1.setOnClickListener( new View.OnClickListener(){
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "+", Toast.LENGTH_SHORT).show();
}
});
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(VHScrollViewActivity.this, "You clicked image button", Toast.LENGTH_LONG).show();
}
});
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView android:id="@+id/scrollview" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:id="@+id/imagebutton1" android:layout_width="100dip" android:layout_height="100dip" android:src="@drawable/sample_0" android:scaleType="fitXY"/>
</.......>