我創建了兩個片段:如何知道點擊了哪個按鈕?
<fragment
android:name="BoxFragment"
android:layout_width="150dp"
android:layout_height="80dp"
android:id="@+id/box_fragment_1"
android:layout_below="@+id/box_fragment_2"
android:layout_alignParentStart="true"
android:layout_marginTop="42dp"
tools:layout="@layout/fragment_box" />
<fragment
android:layout_width="150dp"
android:layout_height="50dp"
android:id="@+id/box_fragment_2"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
tools:layout="@layout/fragment_box" />
這個片段的佈局:
<ImageButton
android:layout_width="197dp"
android:layout_height="197dp"
android:id="@+id/ibPress"
android:layout_gravity="center" />
所以,我註冊OnClickListener:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.fragment_box, container, false);
ImageButton imageButton= (ImageButton) view.findViewById(R.id.ibPress);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(LOG_TAG,this.toString());
//how to know,wich button clicked?
presenter.onButtonClick(...?);
}
});
return view;
}
所以,我想從是什麼片段按鈕知道何苦呢? 我是否需要參考查看presenter.onButtonClick
? 在演示者,我想知道什麼按鈕被按下,然後做一些工作。
謝謝!
第二個片段是否應該沒有「name」標籤? – 0X0nosugar