나는 고정 된 머리글과 바닥 글이있는 ScrollView
입니다. 내 머리글과 바닥 글은 scrollable_contents.xml
레이아웃에 있습니다. 스크롤되는 부분은 contents.xml
입니다. scrollable_contents.xml
개의 버튼을 클릭 할 수있게 만들고 싶습니다. 다음과 같은 작업을 수행했지만 버튼이 클릭되지 않는 것 같습니다. 내 코드와 레이아웃은 다음과 같습니다. 무엇을해야할지 단계별로 안내하십시오.안드로이드의 ScrollView에서 버튼이 클릭되지 않는 이유는 무엇입니까?
scrollable_contents.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>
contents.xml 당신이 버튼을 클릭 리스너를 설정 어디 표시되지 않습니다
<?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>
mycontactstemp.java
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;
}
}
}
버튼에 리스너를 추가 했습니까? 버튼에 대한 클릭 수신기에 – Chaitanya
설정 – SMK