为什么';我的按钮在Android的滚动视图中被点击了吗?
我有一个带有固定页眉和页脚的为什么';我的按钮在Android的滚动视图中被点击了吗?,android,button,onclick,scrollview,Android,Button,Onclick,Scrollview,我有一个带有固定页眉和页脚的滚动视图。我的页眉和页脚位于可滚动内容.xml布局中。滚动的部分位于contents.xml中。我想让中的按钮可滚动\u contents.xml可点击。我做了以下操作,但按钮似乎没有被点击。我的代码和布局如下。请一步一步地指导我做什么 可滚动的内容.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com
滚动视图
。我的页眉和页脚位于可滚动内容.xml
布局中。滚动的部分位于contents.xml
中。我想让中的按钮可滚动\u contents.xml
可点击。我做了以下操作,但按钮似乎没有被点击。我的代码和布局如下。请一步一步地指导我做什么
可滚动的内容.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Header aligned to top -->
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:background="@android:color/white" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="18dp"
android:src="@drawable/propic" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="24dp"
android:layout_toRightOf="@+id/imageView1"
android:text="Jack Reacher"
android:textSize="17dp"
android:textColor="#000" />
</RelativeLayout>
<!-- Footer aligned to bottom -->
<RelativeLayout
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@android:color/white" >
<Button
android:id="@+id/button1"
android:layout_width="160dp"
android:layout_height="50dp"
android:background="@color/green"
android:layout_alignParentTop="true"
android:text="Accept"
android:textSize="17dp"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/button2"
android:layout_width="160dp"
android:layout_height="50dp"
android:textSize="17dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button1"
android:background="@color/red"
android:text="Decline"
android:textColor="#FFFFFF"/>
</RelativeLayout>
<!-- Scrollable Item below header and above footer -->
<ScrollView
android:id="@+id/scrollableContents"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:background="@android:color/white"
android:layout_below="@id/header" >
<!-- Inflate the contents of the ScrollView dynamicaly -->
</ScrollView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="190dp"
android:layout_height="23dp"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:background="@drawable/roundedittext"
android:ems="10"
android:paddingLeft="25dp"
android:text="Task 1"
android:textColor="#FFFFFF"
android:textSize="17dp" >
<requestFocus />
</EditText>
// some more widgets
</RelativeLayout>
我看不出你在哪里设置了按钮上的点击监听器。你确定已经设置好了吗 您可以在xml中设置它,但该方法将在活动中调用,您必须从活动中调用片段的方法
或者在片段中以编程方式设置单击侦听器。是否已将侦听器添加到按钮中?为按钮设置单击侦听器
public class mycontactstemp extends Fragment implements OnClickListener {
EditText statuses,name,desc,times,dates,e7;
Button b1,b2,b3;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scrollable_contents, container,
false);
ScrollView scrollable_contents = (ScrollView)view.findViewById(R.id.scrollableContents);
getActivity().getLayoutInflater().inflate(R.layout.contents, scrollable_contents);
Button b1=(Button)view.findViewById(R.id.button1);
Button b2=(Button)view.findViewById(R.id.button2);
return view;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Button b1=(Button)v.findViewById(R.id.button1);
switch(v.getId())
{
case R.id.button1:
Toast.makeText(getActivity(),"accept clicked",1000).show();
break;
case R.id.button2:
Toast.makeText(getActivity(),"decline clicked",1000).show();
break;
}
}
}