我正在我的主要活动中实现Pakerfeldts 的视图流(特别是“DiffViewFlowExample”),但我不知道如何将点击侦听器添加到我膨胀视图中的 ImageButtons。
那么如何向位于dashboard_view 中的带有@id=regulatoryDocsBtn 的图像按钮添加点击监听器?
以下是代码片段,我提前感谢您的帮助。
主要活动类:
public class Home extends Activity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/**
* Setup the ViewFlow
* w/TitleFlow------------------------------------------
*/
ViewFlow viewFlow = (ViewFlow) findViewById(R.id.viewflow);
DiffAdapter vfAdapter = new DiffAdapter(this);
viewFlow.setAdapter(vfAdapter);
TitleFlowIndicator indicator = (TitleFlowIndicator) findViewById(R.id.viewflowindic);
indicator.setTitleProvider(vfAdapter);
viewFlow.setFlowIndicator(indicator);
}
DiffAdapter 类:注意:膨胀的视图是@这个类的底部。
public class DiffAdapter extends BaseAdapter implements TitleProvider {
private static final int VIEW1 = 0;
private static final int VIEW2 = 1;
private static final int VIEW_MAX_COUNT = VIEW2 + 1;
private final String[] names = { "DashBoard", "ToolBox" };
private LayoutInflater mInflater;
public DiffAdapter(Context context) {
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override(S)...............
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int view = getItemViewType(position);
if (convertView == null) {
switch (view) {
case VIEW1:
convertView = mInflater.inflate(R.layout.dashboard_view, null);
break;
case VIEW2:
convertView = mInflater.inflate(R.layout.toolbox_view, null);
break;
}
}
return convertView;
}
视图之一的片段:dashboard_view.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#10000000"
android:stretchColumns="*" >
<!-- Row 1 -->
<TableRow android:layout_weight="1" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageButton
android:id="@+id/regulatoryDocsBtn"
style="@style/dashBoardimageBtn"
android:src="@drawable/ic_launcher_regulatory" />
<TextView
style="@style/dashBoardTxt"
android:layout_below="@id/regulatoryDocsBtn"
android:text="Regulatory Docs" />
</RelativeLayout>
.....
</TableRow>