동적으로 채워지는 ListView가 있는데 첫 번째 목록의 항목을 클릭하면 ViewFlipper를 사용하여 단추가있는 새 화면으로 전환하려고합니다.Android ViewFlipper 및 ListView
나는 목록에서 항목을 클릭하면 메시지를 표시하도록 OnItemClickListener를 이미 추가했습니다.
문제는 onItemClick() 메서드에서 showNext() 메서드를 추가하면 응용 프로그램이 NullPointerException과 충돌한다는 것입니다.
버튼을 사용하여 목록이있는 화면에서 화면으로 전환하는 플리퍼를 찾고 있습니다.
다음은 내가 사용하고있는 코드 스 니펫입니다. 여기
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
deviceListView = (ListView) findViewById(R.id.deviceList);
listAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1);
setListAdapter(listAdapter);
deviceListView = getListView();
flippy = (ViewFlipper) findViewById(R.id.flipper);
//flippy.setOnClickListener((OnClickListener) this);
//getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
deviceListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView <?> parent, View v, int position, long id)
{
System.out.println("Before Flipper");
flippy.showNext();
System.out.println("After Flipper");
}
});
getApplicationContext().bindService(
new Intent(this, BrowserUpnpService.class),
serviceConnection,
Context.BIND_AUTO_CREATE
);
}
주시면 감사하겠습니다 내가
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<ViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/deviceList"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" >
</Button>
</ViewFlipper>
</FrameLayout>
어떤 도움을 사용하고있는 XML이다.
감사합니다 :)
업데이트 : 여기
내가 무엇입니까 오류 로그입니다 : 여기07-01 12:31:35.548: E/AndroidRuntime(482): FATAL EXCEPTION: main
07-01 12:31:35.548: E/AndroidRuntime(482): java.lang.NullPointerException
07-01 12:31:35.548: E/AndroidRuntime(482): at com.app.browser.BrowseActivity$3.onItemClick(BrowseActivity.java:156)
07-01 12:31:35.548: E/AndroidRuntime(482): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
07-01 12:31:35.548: E/AndroidRuntime(482): at android.widget.ListView.performItemClick(ListView.java:3382)
07-01 12:31:35.548: E/AndroidRuntime(482): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
07-01 12:31:35.548: E/AndroidRuntime(482): at android.os.Handler.handleCallback(Handler.java:587)
07-01 12:31:35.548: E/AndroidRuntime(482): at android.os.Handler.dispatchMessage(Handler.java:92)
07-01 12:31:35.548: E/AndroidRuntime(482): at android.os.Looper.loop(Looper.java:123)
07-01 12:31:35.548: E/AndroidRuntime(482): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-01 12:31:35.548: E/AndroidRuntime(482): at java.lang.reflect.Method.invokeNative(Native Method)
07-01 12:31:35.548: E/AndroidRuntime(482): at java.lang.reflect.Method.invoke(Method.java:521)
07-01 12:31:35.548: E/AndroidRuntime(482): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-01 12:31:35.548: E/AndroidRuntime(482): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-01 12:31:35.548: E/AndroidRuntime(482): at dalvik.system.NativeStart.main(Native Method)
내 주요 활동 클래스의 코드
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, BrowseActivity.class);
spec = tabHost.newTabSpec("device")
.setIndicator("Devices", getResources().getDrawable(R.drawable.ic_launcher))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MediaPlayer.class);
spec = tabHost.newTabSpec("media")
.setIndicator("Media Player", getResources().getDrawable(R.drawable.ic_launcher))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
pls 오류 로그를 게시 ..... –