我正在开发一个Android项目,我的类扩展了ListActivity。问题是,我想在我的活动中实现ActionBar。我知道android java中不允许多重继承。我已经尝试过将Actionbar实现到我的类中,但是我们在这里遇到了一个接口错误。这是我的代码。
public class AudioPlayer extends ListActivity {
MediaPlayer mPlayer;
private android.support.v7.widget.Toolbar toolbarSetting;
String[] songs = {"1", "2a", "3b", "4c", "5d", "6", "7", "8", "9", "10", "11", "12"};
int[] images = {R.raw.mp1, R.raw.mp2, R.raw.mp3, R.raw.mp4, R.raw.mp5, R.raw.mp6, R.raw.mp7, R.raw.mp8, R.raw.mp9, R.raw.mp10, R.raw.mp11, R.raw.mp12};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
toolbarSetting = (Toolbar) findViewById(R.id.toolbar1); // Attaching the layout to the toolbar object
setSupportActionBar(toolbarSetting);
getSupportActionBar().setTitle("Music");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setIcon(R.drawable.gan1);
AudioPlayerCustomAdapter adapter = new AudioPlayerCustomAdapter(this, songs, images);
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Toast.makeText(AudioPlayer.this, "hey" + position, Toast.LENGTH_SHORT).show();
}
}
帮助将受到很多赞赏。