MainActivity.java
package cc.starlabs.ifevent_v2;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import cc.starlabs.ifevent_v2.fragment.MainActivityFragment;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate (Bundle savedInstanceState )
{
super.onCreate (savedInstanceState );
setContentView (R.layout.activity_main );
if (savedInstanceState==null )
{
getSupportFragmentManager ().beginTransaction ().add (R.id.fragment,new MainActivityFragment ()).commit ();
}
}
@Override
public boolean onCreateOptionsMenu (Menu menu )
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater ().inflate (R.menu.menu_main, menu );
return true;
}
@Override
public boolean onOptionsItemSelected (MenuItem item )
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId ();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings )
{
return true;
}
return super.onOptionsItemSelected (item );
}
}
在 Fragment 里使用 MainActivity.this 的时候遇到了 MainActivity is not an enclosing class?
刚开始写 Android...求指教
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.