Android ActivityGroup
Posted
by
Vahag Vardanyan
on Stack Overflow
See other posts from Stack Overflow
or by Vahag Vardanyan
Published on 2011-08-17T19:07:43Z
Indexed on
2012/06/12
16:40 UTC
Read the original article
Hit count: 441
android
|android-listview
I know that ActivityGroup is in the "past", but I want to learn how to use it. So I write a simple TabHost, and want to show different activities using ActivityGroup. Here are the parts of code
Player.java
package player.org;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
public class Player extends TabActivity {
/** Called when the activity is first created. */
private MediaPlayer media=null;
private SeekBar progress;
private View play;
private Progress p;
TabHost tabhost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
Resources res=getResources();
//TabHost tabhost=(TabHost) findViewById(R.id.tabhost);
// tabhost.setup();
tabhost=getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent=new Intent(this,Progress.class);
spec=tabhost.newTabSpec("now playing").setIndicator("Now playing", res.getDrawable(R.drawable.icon))
.setContent(intent);
tabhost.addTab(spec);
intent=new Intent(this,Group.class);
spec=tabhost.newTabSpec("all_songs").setIndicator("All songs", res.getDrawable(R.drawable.songs))
.setContent(intent);
tabhost.addTab(spec);
//intent=new Intent(this,Progress.class);
spec=tabhost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.icon))
.setContent(intent);
tabhost.addTab(spec);
spec=tabhost.newTabSpec("alboom").setIndicator("Alboom", res.getDrawable(R.drawable.icon))
.setContent(intent);
tabhost.addTab(spec);
tabhost.setCurrentTab(0);
}
}
Group.java
import android.os.Bundle;
import android.view.View;
public class Group extends ActivityGroup
{
@Override
public void onCreate(Bundle savedInstanceStated)
{
super.onCreate(savedInstanceStated);
View view = getLocalActivityManager().startActivity("AllSongs",
new Intent(this, AllSongs.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
setContentView(view);
}
AllSongs.java
package player.org;
import java.util.ArrayList;
import android.R.id;
import android.app.ActivityGroup;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
public class AllSongs extends ListActivity{
ArrayList<String> listItem=new ArrayList<String>();
ArrayAdapter<String> adapter;
ListView listView;
//Player p;
TabHost tab;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//p=new Player();
adapter=new ArrayAdapter<String>(this,R.layout.list_item,listItem);
setListAdapter(adapter);
listView=getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(listener);
addItem("vahag");
addItem("vahagvahag");
}
private OnItemClickListener listener=new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Intent intent = new Intent(AllSongs.this,Progress.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Group group= (Group) getParent();
View view=group.getLocalActivityManager().startActivity("Progress",intent).getDecorView();
setContentView(view);
}
};
public void addItem(String s)
{
listItem.add(s);
adapter.notifyDataSetChanged();
}
}
and the Progress.java
package player.org;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.Context;
public class Progress extends Activity {
// Called when the activity is first created.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
So, AllSongs.java
try to change current activity with Progress activity, but when I press on list item, the Programm forsed closed, and logChat says
"08-17 12:49:26.471: ERROR/AndroidRuntime(1500): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'"
I can't figure how to fix this problem, Can anyone helps?
© Stack Overflow or respective owner