问题描述
我有一个TabHost有两个ViewFlippers,每个ViewFlipper里面有三个列表视图。我想离开< - >右键手势侦听ViewFlipper三个列表视图之间滑动。向上/向下运动的列表视图似乎工作,但我似乎无法得到ViewFlipper工作。
Sessions.java(TabActivity)
公共类会话扩展TabActivity {
私人导游指南;
私人字符串LOG_TAG =会话活动;
// TabHost
私人TabHost tabhost;
私人ViewFlipper viewFlipperDay0;
私人ViewFlipper viewFlipperDay1;
私人TextView的trackTitle_day0;
私人TextView的trackTitle_day1;
私人GestureDetector gestureDetectorDay0;
私人GestureDetector gestureDetectorDay1;
私人的ListView lv_day0_trackA;
私人的ListView lv_day0_trackB;
私人的ListView lv_day0_trackC;
私人的ListView lv_day1_trackA;
私人的ListView lv_day1_trackB;
私人的ListView lv_day1_trackC;
私人的ArrayList<会议> sessionList_day0_trackA;
私人的ArrayList<会议> sessionList_day0_trackB;
私人的ArrayList<会议> sessionList_day0_trackC;
私人的ArrayList<会议> sessionList_day1_trackA;
私人的ArrayList<会议> sessionList_day1_trackB;
私人的ArrayList<会议> sessionList_day1_trackC;
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
叠B = this.getIntent()getExtras()。
如果(B!= NULL){
this.guide =(指南)b.getSerializable(GUIDETYPE);
Log.d(LOG_TAG,打通意图引导序列化);
} 其他 {
Log.e(LOG_TAG,无法打通意向引导);
}
的setContentView(R.layout.sessions);
this.trackTitle_day0 =(TextView中)this.findViewById(R.id.session_track_desc_day0);
this.trackTitle_day0.setText(跟踪A);
this.viewFlipperDay0 =(ViewFlipper)this.findViewById(R.id.session_viewflipper_day0);
this.trackTitle_day1 =(TextView中)this.findViewById(R.id.session_track_desc_day1);
this.trackTitle_day1.setText(跟踪A);
this.viewFlipperDay1 =(ViewFlipper)this.findViewById(R.id.session_viewflipper_day1);
this.gestureDetectorDay0 =新GestureDetector(新SessionGestureDetector(this.viewFlipperDay0));
this.gestureDetectorDay1 =新GestureDetector(新SessionGestureDetector(this.viewFlipperDay1));
//设置轨道姿态刷卡与动画(左/右只)
//向上/向下事件和那些过于对角线或squigly被忽略
viewFlipperDay0.setOnTouchListener(新OnTouchListener()
{
公共布尔onTouch(视图V,MotionEvent事件){
如果(gestureDetectorDay0.onTouchEvent(事件)){
返回true;
} 其他 {
返回false;
}
}
});
viewFlipperDay1.setOnTouchListener(新OnTouchListener()
{
公共布尔onTouch(视图V,MotionEvent事件){
如果(gestureDetectorDay1.onTouchEvent(事件)){
返回true;
} 其他 {
返回false;
}
}
});
//加载意见纳入viewflipper
///添加曲目
Log.d(LOG_TAG,创建轨迹视图);
查看view_day0_trackA = LayoutInflater.from(getApplicationContext())膨胀(R.layout.session_track,空)。
查看view_day0_trackB = LayoutInflater.from(getApplicationContext())膨胀(R.layout.session_track,空)。
查看view_day0_trackC = LayoutInflater.from(getApplicationContext())膨胀(R.layout.session_track,空)。
查看view_day1_trackA = LayoutInflater.from(getApplicationContext())膨胀(R.layout.session_track,空)。
查看view_day1_trackB = LayoutInflater.from(getApplicationContext())膨胀(R.layout.session_track,空)。
查看view_day1_trackC = LayoutInflater.from(getApplicationContext())膨胀(R.layout.session_track,空)。
Log.d(LOG_TAG,添加跟踪视图来ViewFlippers);
addViewToDayFlipper0(view_day0_trackA);
addViewToDayFlipper0(view_day0_trackB);
addViewToDayFlipper0(view_day0_trackC);
addViewToDayFlipper1(view_day1_trackA);
addViewToDayFlipper1(view_day1_trackB);
addViewToDayFlipper1(view_day1_trackC);
Log.d(LOG_TAG,分配列表视图);
this.lv_day0_trackA =(ListView控件)view_day0_trackA.findViewById(R.id.SessionListView);
this.lv_day0_trackB =(ListView控件)view_day0_trackB.findViewById(R.id.SessionListView);
this.lv_day0_trackC =(ListView控件)view_day0_trackC.findViewById(R.id.SessionListView);
this.lv_day1_trackA =(ListView控件)view_day1_trackA.findViewById(R.id.SessionListView);
this.lv_day1_trackB =(ListView控件)view_day1_trackB.findViewById(R.id.SessionListView);
this.lv_day1_trackC =(ListView控件)view_day1_trackC.findViewById(R.id.SessionListView);
//http://pareshnmayani.word$p$pss.com/tag/android-custom-listview-example/
//获取会话
//this.guide = this.getGuide();
Log.d(LOG_TAG,为每个轨道获取会议信息);
this.sessionList_day0_trackA = guide.getSessionsByTrack(0,0);
this.sessionList_day0_trackB = guide.getSessionsByTrack(0,1);
this.sessionList_day0_trackC = guide.getSessionsByTrack(0,2);
this.sessionList_day1_trackA = guide.getSessionsByTrack(1,0);
this.sessionList_day1_trackB = guide.getSessionsByTrack(1,1);
this.sessionList_day1_trackC = guide.getSessionsByTrack(1,2);
Log.d(LOG_TAG,分配SessionAdapters);
最后SessionListAdapter lv_day0_trackA_adapter =新SessionListAdapter(这一点,this.sessionList_day0_trackA);
最后SessionListAdapter lv_day0_trackB_adapter =新SessionListAdapter(这一点,this.sessionList_day0_trackB);
最后SessionListAdapter lv_day0_trackC_adapter =新SessionListAdapter(这一点,this.sessionList_day0_trackC);
最后SessionListAdapter lv_day1_trackA_adapter =新SessionListAdapter(这一点,this.sessionList_day1_trackA);
最后SessionListAdapter lv_day1_trackB_adapter =新SessionListAdapter(这一点,this.sessionList_day1_trackB);
最后SessionListAdapter lv_day1_trackC_adapter =新SessionListAdapter(这一点,this.sessionList_day1_trackC);
Log.d(LOG_TAG,设置适配器);
lv_day0_trackA.setAdapter(lv_day0_trackA_adapter);
lv_day0_trackB.setAdapter(lv_day0_trackB_adapter);
lv_day0_trackC.setAdapter(lv_day0_trackC_adapter);
lv_day1_trackA.setAdapter(lv_day1_trackA_adapter);
lv_day1_trackB.setAdapter(lv_day1_trackB_adapter);
lv_day1_trackC.setAdapter(lv_day1_trackC_adapter);
Log.d(LOG_TAG,ListView控件OnClickListenters被分配);
lv_day0_trackA.setOnItemClickListener(新AdapterView.OnItemClickListener(){
公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT位置,长的id){
//项目点击监听器列表视图
会议会议=(会话)lv_day0_trackA_adapter.getItem(位置);
Toast.makeText(getApplicationContext(),标题=>中+ session.getTitle()+\ n个=>中+ session.getTimeSpan(),Toast.LENGTH_SHORT).show();
}
});
lv_day0_trackB.setOnItemClickListener(新AdapterView.OnItemClickListener(){
公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT位置,长的id){
//项目点击监听器列表视图
会议会议=(会话)lv_day0_trackB_adapter.getItem(位置);
Toast.makeText(getApplicationContext(),标题=>中+ session.getTitle()+\ n个=>中+ session.getTimeSpan(),Toast.LENGTH_SHORT).show();
}
});
lv_day0_trackC.setOnItemClickListener(新AdapterView.OnItemClickListener(){
公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT位置,长的id){
//项目点击监听器列表视图
会议会议=(会话)lv_day0_trackC_adapter.getItem(位置);
Toast.makeText(getApplicationContext(),标题=>中+ session.getTitle()+\ n个=>中+ session.getTimeSpan(),Toast.LENGTH_SHORT).show();
}
});
lv_day1_trackA.setOnItemClickListener(新AdapterView.OnItemClickListener(){
公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT位置,长的id){
//项目点击监听器列表视图
会议会议=(会话)lv_day1_trackA_adapter.getItem(位置);
Toast.makeText(getApplicationContext(),标题=>中+ session.getTitle()+\ n个=>中+ session.getTimeSpan(),Toast.LENGTH_SHORT).show();
}
});
lv_day1_trackB.setOnItemClickListener(新AdapterView.OnItemClickListener(){
公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT位置,长的id){
//项目点击监听器列表视图
会议会议=(会话)lv_day1_trackB_adapter.getItem(位置);
Toast.makeText(getApplicationContext(),标题=>中+ session.getTitle()+\ n个=>中+ session.getTimeSpan(),Toast.LENGTH_SHORT).show();
}
});
lv_day1_trackC.setOnItemClickListener(新AdapterView.OnItemClickListener(){
公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT位置,长的id){
//项目点击监听器列表视图
会议会议=(会话)lv_day1_trackC_adapter.getItem(位置);
Toast.makeText(getApplicationContext(),标题=>中+ session.getTitle()+\ n个=>中+ session.getTimeSpan(),Toast.LENGTH_SHORT).show();
}
});
tabhost = getTabHost();
。tabhost.getTabWidget()setDividerDrawable(R.drawable.tab_divider);
tabhost.addTab(tabhost.newTabSpec(day0)setIndicator(createTabView(tabhost.getContext(),星期五))setContent(R.id.session_tab_layout_day0));
tabhost.addTab(tabhost.newTabSpec(第1天)setIndicator(createTabView(tabhost.getContext(),星期六))setContent(R.id.session_tab_layout_day1));
tabhost.setCurrentTab(0);
Log.d(LOG_TAG,完了吗?);
};
私有静态视图createTabView(最终上下文的背景下,最终的文本字符串){
查看查看= LayoutInflater.from(上下文).inflate(R.layout.tabs_bg,NULL);
TextView的电视=(TextView中)view.findViewById(R.id.tabsText);
tv.setText(文本);
返回查看;
}
//添加以viewflipper
公共无效addViewToDayFlipper0(查看视图){
viewFlipperDay0.addView(视图);
}
公共无效addViewToDayFlipper1(查看视图){
viewFlipperDay1.addView(视图);
}
//自定义手势适配器
公共类SessionGestureDetector扩展SimpleOnGestureListener {
私有静态最终诠释SWIPE_MIN_DISTANCE = 120;
私有静态最终诠释SWIPE_MAX_OFF_PATH = 250;
私有静态最终诠释SWIPE_THRESHOLD_VELOCITY = 200;
私人ViewFlipper VF;
公共SessionGestureDetector(最终ViewFlipper VF){
超();
this.vf = VF;
}
公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,浮velocityY){
的System.out.println(在onFling()::);
如果(Math.abs(e1.getY() - e2.getY())> SWIPE_MAX_OFF_PATH)
返回false;
如果(e1.getX() - e2.getX()> SWIPE_MIN_DISTANCE
&功放;&安培; Math.abs(velocityX)> SWIPE_THRESHOLD_VELOCITY){
vf.setInAnimation(inFromRightAnimation());
vf.setOutAnimation(outToLeftAnimation());
vf.showNext();
}否则,如果(e2.getX() - e1.getX()> SWIPE_MIN_DISTANCE
&功放;&安培; Math.abs(velocityX)> SWIPE_THRESHOLD_VELOCITY){
vf.setInAnimation(inFromLeftAnimation());
vf.setOutAnimation(outToRightAnimation());
vf.show previous();
}
返回super.onFling(E1,E2,velocityX,velocityY);
}
}
私人动画inFromRightAnimation(){
动画inFromRight =新TranslateAnimation(
Animation.RELATIVE_TO_PARENT,+ 1.0F,
Animation.RELATIVE_TO_PARENT,0.0,
Animation.RELATIVE_TO_PARENT,0.0,
Animation.RELATIVE_TO_PARENT,0.0);
inFromRight.setDuration(500);
inFromRight.setInterpolator(新AccelerateInterpolator());
返回inFromRight;
}
私人动画outToLeftAnimation(){
动画outtoLeft =新TranslateAnimation(
Animation.RELATIVE_TO_PARENT,0.0,
Animation.RELATIVE_TO_PARENT,-1.0F,
Animation.RELATIVE_TO_PARENT,0.0,
Animation.RELATIVE_TO_PARENT,0.0);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(新AccelerateInterpolator());
返回outtoLeft;
}
私人动画inFromLeftAnimation(){
动画inFromLeft =新TranslateAnimation(
Animation.RELATIVE_TO_PARENT,-1.0F,
Animation.RELATIVE_TO_PARENT,0.0,
Animation.RELATIVE_TO_PARENT,0.0,
Animation.RELATIVE_TO_PARENT,0.0);
inFromLeft.setDuration(500);
inFromLeft.setInterpolator(新AccelerateInterpolator());
返回inFromLeft;
}
私人动画outToRightAnimation(){
动画outtoRight =新TranslateAnimation(
Animation.RELATIVE_TO_PARENT,0.0,
Animation.RELATIVE_TO_PARENT,+ 1.0F,
Animation.RELATIVE_TO_PARENT,0.0,
Animation.RELATIVE_TO_PARENT,0.0);
outtoRight.setDuration(500);
outtoRight.setInterpolator(新AccelerateInterpolator());
返回outtoRight;
}
}
sessions.xml
< XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =center_vertical
机器人:后台=#222222>
< TabWidget机器人:ID =@机器人:ID /标签
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/>
<的FrameLayout机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout机器人:ID =@ + ID / session_tab_layout_day0
机器人:方向=垂直
机器人:layout_height =FILL_PARENT
机器人:layout_width =FILL_PARENT
机器人:后台=#F0E0B2>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:重力=center_horizontal
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=#8e9f13
机器人:后台=#006772
机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:ID =@ + ID / session_track_desc_day0
机器人:文本=@字符串/ session_track>< / TextView的>
< ViewFlipper
机器人:ID =@ + ID / session_viewflipper_day0
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>
< / ViewFlipper>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / session_tab_layout_day1
机器人:方向=垂直
机器人:layout_height =FILL_PARENT
机器人:layout_width =FILL_PARENT
机器人:后台=#F0E0B2>
<的TextView
机器人:layout_width =FILL_PARENT
机器人:重力=center_horizontal
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=#8e9f13
机器人:后台=#006772
机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:ID =@ + ID / session_track_desc_day1
机器人:文本=@字符串/ session_track>< / TextView的>
< ViewFlipper
机器人:ID =@ + ID / session_viewflipper_day1
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>
< / ViewFlipper>
< / LinearLayout中>
< /的FrameLayout>
< / LinearLayout中>
< / TabHost>
session_track.xml
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / session_list
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:后台=#F0E0B2>
<的ListView
机器人:ID =@ + ID / SessionListView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>
session_two_line_list.xml
< XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =70dip
机器人:填充=6dip>
<的TextView
机器人:ID =@ + ID / session_title
机器人:文本=课程名称
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=center_vertical
机器人:TEXTSIZE =22dip
机器人:文字颜色=#006772/>
<的TextView
机器人:ID =@ + ID / session_time
机器人:文本=08:00-09:00
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:单线=真
机器人:TEXTSIZE =13dip
机器人:文字颜色=#006772/>
< / LinearLayout中>
不要使用ViewFlipper,使用的。这是一个相对较晚除了为正是这种图形用户界面的创建的SDK。
I have a TabHost that has two ViewFlippers, and inside each ViewFlipper are three ListViews. I would like to have left<->right gesture listener for the ViewFlipper to slide between the three ListViews. The Up/Down motion for the ListViews seems to work, but I cannot seem to get the ViewFlipper to work.
Sessions.java (TabActivity)
public class Sessions extends TabActivity {
private Guide guide;
private String LOG_TAG = "Sessions Activity";
// TabHost
private TabHost tabhost;
private ViewFlipper viewFlipperDay0;
private ViewFlipper viewFlipperDay1;
private TextView trackTitle_day0;
private TextView trackTitle_day1;
private GestureDetector gestureDetectorDay0;
private GestureDetector gestureDetectorDay1;
private ListView lv_day0_trackA;
private ListView lv_day0_trackB;
private ListView lv_day0_trackC;
private ListView lv_day1_trackA;
private ListView lv_day1_trackB;
private ListView lv_day1_trackC;
private ArrayList<Session> sessionList_day0_trackA;
private ArrayList<Session> sessionList_day0_trackB;
private ArrayList<Session> sessionList_day0_trackC;
private ArrayList<Session> sessionList_day1_trackA;
private ArrayList<Session> sessionList_day1_trackB;
private ArrayList<Session> sessionList_day1_trackC;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = this.getIntent().getExtras();
if (b!=null) {
this.guide = (Guide) b.getSerializable(GUIDETYPE);
Log.d(LOG_TAG,"Got guide through intent Serializable");
} else {
Log.e(LOG_TAG,"Unable to get guide through Intent");
}
setContentView(R.layout.sessions);
this.trackTitle_day0 = (TextView) this.findViewById(R.id.session_track_desc_day0);
this.trackTitle_day0.setText("Track A");
this.viewFlipperDay0 = (ViewFlipper) this.findViewById(R.id.session_viewflipper_day0);
this.trackTitle_day1 = (TextView) this.findViewById(R.id.session_track_desc_day1);
this.trackTitle_day1.setText("Track A");
this.viewFlipperDay1 = (ViewFlipper) this.findViewById(R.id.session_viewflipper_day1);
this.gestureDetectorDay0 = new GestureDetector(new SessionGestureDetector(this.viewFlipperDay0));
this.gestureDetectorDay1 = new GestureDetector(new SessionGestureDetector(this.viewFlipperDay1));
// set up gesture swiping of tracks with animations (left/right only)
// up/down events and those which are too diagonal or squigly are ignored
viewFlipperDay0.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetectorDay0.onTouchEvent(event)) {
return true;
} else {
return false;
}
}
});
viewFlipperDay1.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetectorDay1.onTouchEvent(event)) {
return true;
} else {
return false;
}
}
});
// load views into viewflipper
/// Add Tracks
Log.d(LOG_TAG,"Creating Track Views");
View view_day0_trackA = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
View view_day0_trackB = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
View view_day0_trackC = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
View view_day1_trackA = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
View view_day1_trackB = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
View view_day1_trackC = LayoutInflater.from(getApplicationContext()).inflate(R.layout.session_track, null);
Log.d(LOG_TAG,"Adding Track Views to ViewFlippers");
addViewToDayFlipper0(view_day0_trackA);
addViewToDayFlipper0(view_day0_trackB);
addViewToDayFlipper0(view_day0_trackC);
addViewToDayFlipper1(view_day1_trackA);
addViewToDayFlipper1(view_day1_trackB);
addViewToDayFlipper1(view_day1_trackC);
Log.d(LOG_TAG,"Assigning ListViews");
this.lv_day0_trackA = (ListView) view_day0_trackA.findViewById(R.id.SessionListView);
this.lv_day0_trackB = (ListView) view_day0_trackB.findViewById(R.id.SessionListView);
this.lv_day0_trackC = (ListView) view_day0_trackC.findViewById(R.id.SessionListView);
this.lv_day1_trackA = (ListView) view_day1_trackA.findViewById(R.id.SessionListView);
this.lv_day1_trackB = (ListView) view_day1_trackB.findViewById(R.id.SessionListView);
this.lv_day1_trackC = (ListView) view_day1_trackC.findViewById(R.id.SessionListView);
//http://pareshnmayani.wordpress.com/tag/android-custom-listview-example/
// get sessions
//this.guide = this.getGuide();
Log.d(LOG_TAG,"Getting Session info for each track");
this.sessionList_day0_trackA = guide.getSessionsByTrack(0,0);
this.sessionList_day0_trackB = guide.getSessionsByTrack(0,1);
this.sessionList_day0_trackC = guide.getSessionsByTrack(0,2);
this.sessionList_day1_trackA = guide.getSessionsByTrack(1,0);
this.sessionList_day1_trackB = guide.getSessionsByTrack(1,1);
this.sessionList_day1_trackC = guide.getSessionsByTrack(1,2);
Log.d(LOG_TAG,"Assigning SessionAdapters");
final SessionListAdapter lv_day0_trackA_adapter = new SessionListAdapter(this, this.sessionList_day0_trackA);
final SessionListAdapter lv_day0_trackB_adapter = new SessionListAdapter(this, this.sessionList_day0_trackB);
final SessionListAdapter lv_day0_trackC_adapter = new SessionListAdapter(this, this.sessionList_day0_trackC);
final SessionListAdapter lv_day1_trackA_adapter = new SessionListAdapter(this, this.sessionList_day1_trackA);
final SessionListAdapter lv_day1_trackB_adapter = new SessionListAdapter(this, this.sessionList_day1_trackB);
final SessionListAdapter lv_day1_trackC_adapter = new SessionListAdapter(this, this.sessionList_day1_trackC);
Log.d(LOG_TAG,"Setting Adapters");
lv_day0_trackA.setAdapter(lv_day0_trackA_adapter);
lv_day0_trackB.setAdapter(lv_day0_trackB_adapter);
lv_day0_trackC.setAdapter(lv_day0_trackC_adapter);
lv_day1_trackA.setAdapter(lv_day1_trackA_adapter);
lv_day1_trackB.setAdapter(lv_day1_trackB_adapter);
lv_day1_trackC.setAdapter(lv_day1_trackC_adapter);
Log.d(LOG_TAG,"ListView OnClickListenters being assigned");
lv_day0_trackA.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// item click listener for listview
Session session = (Session) lv_day0_trackA_adapter.getItem(position);
Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
}
});
lv_day0_trackB.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// item click listener for listview
Session session = (Session) lv_day0_trackB_adapter.getItem(position);
Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
}
});
lv_day0_trackC.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// item click listener for listview
Session session = (Session) lv_day0_trackC_adapter.getItem(position);
Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
}
});
lv_day1_trackA.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// item click listener for listview
Session session = (Session) lv_day1_trackA_adapter.getItem(position);
Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
}
});
lv_day1_trackB.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// item click listener for listview
Session session = (Session) lv_day1_trackB_adapter.getItem(position);
Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
}
});
lv_day1_trackC.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// item click listener for listview
Session session = (Session) lv_day1_trackC_adapter.getItem(position);
Toast.makeText(getApplicationContext(), "Title => "+session.getTitle()+" \n Time => "+session.getTimeSpan(), Toast.LENGTH_SHORT).show();
}
});
tabhost = getTabHost();
tabhost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
tabhost.addTab(tabhost.newTabSpec("day0").setIndicator(createTabView(tabhost.getContext(), "Friday")).setContent(R.id.session_tab_layout_day0));
tabhost.addTab(tabhost.newTabSpec("day1").setIndicator(createTabView(tabhost.getContext(), "Saturday")).setContent(R.id.session_tab_layout_day1));
tabhost.setCurrentTab(0);
Log.d(LOG_TAG,"Finished?");
};
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
// Add view to viewflipper
public void addViewToDayFlipper0(View view) {
viewFlipperDay0.addView(view);
}
public void addViewToDayFlipper1(View view) {
viewFlipperDay1.addView(view);
}
// Custom Gesture Adapter
public class SessionGestureDetector extends SimpleOnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private ViewFlipper vf;
public SessionGestureDetector(final ViewFlipper vf) {
super();
this.vf = vf;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
System.out.println(" in onFling() :: ");
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
vf.setInAnimation(inFromRightAnimation());
vf.setOutAnimation(outToLeftAnimation());
vf.showNext();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
vf.setInAnimation(inFromLeftAnimation());
vf.setOutAnimation(outToRightAnimation());
vf.showPrevious();
}
return super.onFling(e1, e2, velocityX, velocityY);
}
}
private Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
private Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
private Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(500);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
private Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
}
sessions.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:background="#222222">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/session_tab_layout_day0"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#F0E0B2">
<TextView
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:textColor="#8e9f13"
android:background="#006772"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/session_track_desc_day0"
android:text="@string/session_track"></TextView>
<ViewFlipper
android:id="@+id/session_viewflipper_day0"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ViewFlipper>
</LinearLayout>
<LinearLayout android:id="@+id/session_tab_layout_day1"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#F0E0B2">
<TextView
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:textColor="#8e9f13"
android:background="#006772"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/session_track_desc_day1"
android:text="@string/session_track"></TextView>
<ViewFlipper
android:id="@+id/session_viewflipper_day1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ViewFlipper>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
session_track.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/session_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F0E0B2">
<ListView
android:id="@+id/SessionListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
session_two_line_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="70dip"
android:padding="6dip">
<TextView
android:id="@+id/session_title"
android:text="Session Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="22dip"
android:textColor="#006772"/>
<TextView
android:id="@+id/session_time"
android:text="08:00-09:00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="13dip"
android:textColor="#006772" />
</LinearLayout>
Don't use a ViewFlipper, use a ViewPager. It's a relatively late addition to the SDK that was created for exactly this sort of GUI.
这篇关于TabHost与多个ViewFlippers - GestureListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!