탭이 3 개인 탭 기능이 있습니다. 탭 중 하나에는 ListActivity가 있고 다른 두 개의 탭에는 간단한 활동이 들어 있습니다. 그리고 나는 Fling 이벤트의 탭을 변경하기 위해 OnGestureListener를 구현했습니다.Android : 플링 제스처 이벤트의 탭 변경 - TabActivity 내부의 ListActivity에 대해 작동하지 않습니다.
onTouchEvent
및 'onFling'이벤트는 ListActivity가있는 탭에 대해 호출되지 않습니다. 그러나 Simple Activity (목록 없음)에 대해서는 정상적으로 작동합니다.
주요 활동 클래스 :
public class GestureTest extends TabActivity implements OnGestureListener {
private TabHost tabHost;
private GestureDetector gestureScanner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testmainlayoutforgesture);
gestureScanner = new GestureDetector(this);
addTabs();
}
private void addTabs() {
Intent i1 = new Intent().setClass(this, SimpleListActivity.class);
Intent i2 = new Intent().setClass(this, SimpleActivity.class);
Intent i3 = new Intent().setClass(this, SimpleActivity.class);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("First").setIndicator("First").setContent(i1));
tabHost.addTab(tabHost.newTabSpec("Second").setIndicator("Second").setContent(i2));
tabHost.addTab(tabHost.newTabSpec("Third").setIndicator("Third").setContent(i3));
tabHost.setCurrentTab(0);
}
@Override
public boolean onTouchEvent(MotionEvent me) {
return gestureScanner.onTouchEvent(me);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
float dispX = e2.getX() - e1.getX();
float dispY = e2.getY() - e1.getY();
if (Math.abs(dispX) >= 200 && Math.abs(dispY) <= 100) {
// swipe ok
if (dispX > 0) {
// L-R swipe
System.out.println("L-R swipe");
changeLtoR();
} else {
// R-L swipe
System.out.println("R-L swipe");
}
}
return true;
}
private void changeLtoR() {
int curTab = tabHost.getCurrentTab();
int nextTab = ((curTab + 1) % 3);
tabHost.setCurrentTab(nextTab);
}
//other interface methods
}
SimpleListActivity.java :
public class SimpleListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<String> list1Strings = new ArrayList<String>();
list1Strings.add("List 11");
list1Strings.add("List 12");
list1Strings.add("List 13");
list1Strings.add("List 14");
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings));
}
}
SimpleActivity.java :
,691 여기 내 코드입니다 363,210public class SimpleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simplelayouttest);
}
}
testmainlayoutforgesture.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
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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">
</FrameLayout>
</LinearLayout>
</TabHost>
simplelayouttest.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="fill_parent">
<TextView
android:id="@+id/helloTv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello Hello" />
</LinearLayout>
내가 여기에 잘못이 무엇인지 알아낼 수 없었다. 당신의 TabActivity이 추가
감사합니다. 나는 너의 '또 다른 가능성'을 이해할 수 없었다. 네, 내 원래의 코드는 내 앱의 헤더 (앱 이름이 표시되는 섹션)에서 튀어 오르는 경우에 fling 이벤트에서 작동했습니다. – gtiwari333
하지만이 방법으로 또 다른 문제점을 발견했습니다. 항목 중 아무 것도 터치 할 수 없습니다. 즉, 목록 항목과 탭을 선택 (터치) 할 수 없습니다. – gtiwari333
여기에 솔루션을 게시 할 수 있습니까? – kaspermoerch