我想在列表视图中实现一个 ActionBar。正如 developer.android.com 中给出的那样,我尝试在我的代码中使用扩展 ActionBar 活动。当我提供扩展 Activity 时,我的代码运行良好,但我不会得到 ActionBar。当我使用带有 java.lang.exceptionininitializererror 的扩展 ActionBarActivity 时,代码崩溃。
我已经导入了支持库。附上截图。导入的库是 android-support-v4.jar android-support-v7-appcompat.jar。
下面是我的代码。请指导我。
另外请让我知道我是否可以使用任何其他方式来做到这一点。
public class ImageTextListViewActivity extends Activity implements OnItemClickListener {
public static final String[] titles = new String[] { "Football",
"Basketball" };
public static final Integer[] images = { R.drawable.football,
R.drawable.basketball };
ListView listView;
List<RowItem> rowItems;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//ActionBar actionBar = getSupportActionBar();
// actionBar.setDisplayShowTitleEnabled(false);
//android.graphics.drawable.ColorDrawable.setColor(0xff9ACC00);
//actionBar.setBackgroundDrawable(colorDrawable);
//actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem(images[i], titles[i]);
rowItems.add(item);
}
listView = (ListView) findViewById(R.id.list);
CustomListViewAdapter adapter = new CustomListViewAdapter(this,
R.layout.list_item, rowItems);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//Navigation to next page
Intent myIntent = new Intent(view.getContext(), Football.class);
myIntent.putExtra("Game",listView.getItemAtPosition(position).toString());
startActivityForResult(myIntent, 0);
//Navigation ends
}
}