Android课程设计,个人日程app
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //显示已有的数据 final ListView listView = (ListView) findViewById(R.id.listview); final DBHelper helper = new DBHelper(MainActivity.this); SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, helper.queryAll(), R.layout.item, new String[]{"id", "date", "schedule"}, new int[]{R.id.schedule_id, R.id.schedule_date, R.id.schedule_text}); listView.setAdapter(adapter); //设置长按事件 listView.setOnCreateContextMenuListener(listviewLongPress); // 设置点击进入详情页 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(MainActivity.this, TextActivity.class); List<String> listdata; List<String> listtext; listdata = helper.queryDate(); listtext = helper.querySchedule(); String date = listdata.get(position) ""; String schedule = listtext.get(position) ""; intent.putExtra("date", date); intent.putExtra("schedule", schedule); startActivity(intent); } }); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { addNewSchedule(); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this);
评论