我目前有一個tabview
以及3個選項卡。 1選項卡加載ActivityGroup
,然後加載listview
。我有這個,所以我可以加載不同的活動和查看,並仍然顯示選項卡。當我點擊我的listview
上的第一個項目時,它會完美加載所有內容,並且完全按照我希望的方式執行。但是,當我點擊列表中的第二項時,我得到一個日誌貓錯誤。它應該加載一個新的活動和新的視圖。我不知道我是否正確地做了這件事,並真的很感謝幫助。代碼和日誌貓在下面。Android-活動組在點擊列表視圖項目時不啓動新活動
播放列表組類:
public class PlaylistGroup extends ActivityGroup{
public static PlaylistGroup group;
// Need to keep track of the history if you want the back-button to work properly,
//don't use this if your activities requires a lot of memory.
private ArrayList<View> history;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.history = new ArrayList<View>();
group = this;
// Start the root activity within the group and get its view
View view = getLocalActivityManager().startActivity("PlaylistActivity", new
Intent(this,PlaylistActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Replace the view of this ActivityGroup
replaceView(view);
}
public void replaceView(View v) {
// Adds the old one to history
history.add(v);
// Changes this Groups View to the new View.
setContentView(v);
}
//so you can go back and forth and keep the tab layout
public void back() {
if(history.size() > 0) {
history.remove(history.size()-1);
setContentView(history.get(history.size()-1));
}else {
finish();
}
}
public void onBackPressed() {
PlaylistGroup.group.back();
return;
}
的ListView類:
public class PlaylistActivity extends ListActivity{
private static final String TAG = PlaylistActivity.class.getSimpleName();
// Data to put in the ListAdapter
private String[] sdrPlaylistNames = new String[] {
"Best of June 2011", "Best of May 2011", "Dubstep",
"House", "Other"};
private ListAdapter sdrListAdapter;
Intent playbackServiceIntent, playbackServiceIntent1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playlists_layout);
//fill the screen with the list adapter
playlistFillData();
}
public void playlistFillData() {
//create and set up the Array adapter for the list view
ArrayAdapter sdrListAdapter = new ArrayAdapter(this, R.layout.list_item, sdrPlaylistNames);
setListAdapter(sdrListAdapter);
}
//set up the on list item Click
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
//create a switch so that each list item is a different playlist
switch(position){
case 0:
Intent BOJintent = new Intent(this, BOJAudioActivity.class);
// Create the view using PlaylistGroup's LocalActivityManager
View view = PlaylistGroup.group.getLocalActivityManager()
.startActivity("show_city", BOJintent
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Again, replace the view
PlaylistGroup.group.replaceView(view);
playbackServiceIntent = new Intent(this, BOJAudioService.class);
Log.d(TAG, "Made Intent");
startService(playbackServiceIntent);
Log.d(TAG, "started Service");
break;
case 1:
Log.d(TAG, "stop service");
getApplicationContext().stopService(playbackServiceIntent);
Log.d(TAG, "service stopp'd");
Intent BOJintenttest = new Intent(this, TestActivity.class);
// Create the view using PlaylistGroup's LocalActivityManager
View view2 = PlaylistGroup.group.getLocalActivityManager()
.startActivity("show_city", BOJintenttest
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Again, replace the view
//PlaylistGroup.group.replaceView(view2);
// Log.d(TAG, "Made Intent");
// startActivity(BOJintenttest);
// Log.d(TAG, "started a");
break;
case 2:
break;
}
}
}
LOG CAT:
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): FATAL EXCEPTION: main
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): android.content.ActivityNotFoundException: Unable to find explicit activity class {ravebox.dev.sdr/ravebox.dev.sdr.TestActivity}; have you declared this activity in your AndroidManifest.xml?
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:1568)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:277)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at ravebox.dev.sdr.PlaylistActivity.onListItemClick(PlaylistActivity.java:74)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.widget.ListView.performItemClick(ListView.java:3513)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.os.Handler.handleCallback(Handler.java:587)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.os.Handler.dispatchMessage(Handler.java:92)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.os.Looper.loop(Looper.java:123)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at android.app.ActivityThread.main(ActivityThread.java:3835)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at java.lang.reflect.Method.invokeNative(Native Method)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at java.lang.reflect.Method.invoke(Method.java:507)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-14 12:19:12.291: ERROR/AndroidRuntime(6810): at dalvik.system.NativeStart.main(Native Method)
這真的有竅門!是否有原因爲什麼不能像以前那樣設置活動? – Splitusa
我不是100%確切地知道它爲什麼是這樣,但你只需要一個MAIN和DEFAULT/LAUNCHER就是它,我很確定。 – Rob
明白了。那麼我會確保改變我所有的其他活動。再次感謝! – Splitusa