私はチュートリアルアプリを作成しようとしています。これは私の主な活動の全体のコードではありません - 私はノート Androidスタジオナビゲーションドロワー - 表現が必要
case 2: Activity = new Lesson111(); break;
下
式が
を期待というメッセージを取得しています。しかし、問題は、私はここで
case 2:
Activity = new Lesson111();
break;
に
case 2:
fragment = new Lesson111();
break;
を変更したときに起動する私のMain.Activityです:
public class NavigationActivity extends FragmentActivity {
private DrawerLayout mDrawerLayout;
ImageView home;
Fragment fragment = null;
TextView appname;
ExpandableListView expListView;
HashMap<String, List<String>> listDataChild;
ExpandableListAdapter listAdapter;
List<String> listDataHeader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation);
home = (ImageView)findViewById(R.id.home);
home.setOnClickListener(homeOnclickListener);
appname = (TextView)findViewById(R.id.appname);
setUpDrawer();
}
/**
*
* Get the names and icons references to build the drawer menu...
*/
private void setUpDrawer() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));
mDrawerLayout.setDrawerListener(mDrawerListener);
expListView = (ExpandableListView) findViewById(R.id.lvExp);
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
fragment = new Lesson1();
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerLayout.closeDrawer(expListView);
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
switch (groupPosition) {
case 0:
switch (childPosition) {
case 0:
fragment = new Lesson1();
break;
case 1:
fragment = new Lesson11();
break;
case 2:
Activity = new Lesson111();
break;
default:
break;
}
break;
アクティビティ変数を初期化しないでください。 Activity activity = new Lesson111();のようなものを試してみてください。 –
私はあなたが言ったことを試みました。しかし、それは互換性のないタイプです。また、「アクティビティ」もグレー表示されます。また、それも言います - 必須:android.app.Activity Found:com.android.pet.view.Lesson111 –
実際にアクティビティインスタンスをインスタンス化していないためです。今はちょうどそこにぶら下がっています。あなたは何を達成しようとしていますか?詳細をあなたの質問を更新してください –