我创建了两个片段:如何知道点击了哪个按钮?
<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