我想从listview 中的 mysql 表中获取数据。我想在我的日历下方的列表视图中显示该数据。任何人都可以以简单的方式帮助我。我对此进行了很多搜索,但没有找到合适的解决方案。这是我的代码。帮助将不胜感激。
public class ActionList extends ListActivity {
public static String date;
public static String custname;
public static String starttime;
public static String endtime;
public static String task;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actionlist);
Button plusBtn = (Button) findViewById(R.id.plusBtn);
Button buttonLogout = (Button) findViewById(R.id.btnLogout);
LoginActivity dao = new LoginActivity();
try {
Statement stmt = dao.dbConnection().createStatement();
String sql = "select * from task_tab";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println("This Is rs DAta "
+ rs.getString(1).toString());
date = rs.getString(2).toString();
task = rs.getString(3).toString();
custname = rs.getString(5).toString();
starttime = rs.getString(8).toString();
endtime = rs.getString(9).toString();
}
String[] list2 = { date, task, custname, starttime, endtime };
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list2));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
plusBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent listActivityIntent = new Intent(ActionList.this,
CalendarView.class);
ActionList.this.startActivity(listActivityIntent);
}
});
buttonLogout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),
LoginActivity.class);
intent.putExtra("LoginMessage", "Logged Out");
startActivity(intent);
removeDialog(0);
}
});
}