2014-05-21 1 views
0

나는 고정 된 머리글과 바닥 글이있는 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; 
    } 
} 
} 
+1

버튼에 리스너를 추가 했습니까? 버튼에 대한 클릭 수신기에 – Chaitanya

+1

설정 – SMK

답변

2

. 그것이 설정되어 있는지 확인 하시겠습니까?

xml로 설정할 수도 있지만 해당 작업에서 해당 메서드가 호출되고 해당 작업에서 해당 프래그먼트의 메서드를 호출해야합니다.

조각 내에서 프로그래밍 방식으로 클릭 수신기를 설정하십시오.

관련 문제