如何从MS sql server获取数据和显示?数据库和应用程序之间的连接已完成。如何添加查询和显示?我想知道或者任何人得到任何链接来教它们可以发布它。
TextView txtuserid, txtusername, txtcompany, txtposition, txtdob;
SharedPreferences shp;
ConnectionClass connectionClass;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
txtuserid = (TextView) findViewById(R.id.txtuserid);
txtusername = (TextView) findViewById(R.id.txtusername);
txtcompany = (TextView) findViewById(R.id.txtcompany);
txtposition = (TextView) findViewById(R.id.txtposition);
txtdob = (TextView) findViewById(R.id.txtdob);
shp = this.getSharedPreferences("UserInfo", MODE_PRIVATE);
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) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
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.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_profile) {
} else if (id == R.id.nav_dashboard) {
Intent myIntent = new Intent(Profile.this,
Dashboard.class);
startActivity(myIntent);
} else if (id == R.id.nav_logout) {
LogOut();
return true;
} else if (id == R.id.nav_home) {
Intent myIntent = new Intent(Profile.this,
MainActivity.class);
startActivity(myIntent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void LogOut() {
SharedPreferences.Editor edit = shp.edit();
edit.putString("UserId", "");
edit.commit();
Intent intent = new Intent(Profile.this, LoginActivity.class);
startActivity(intent);
this.finish();
}