如何在android中将mysql数据导入listview

时间:2013-09-12 06:31:44

标签: android mysql listview android-listview

我想在listview中获取来自mysql表的数据。我想在我的calander下面的listview中显示数据。任何人都可以用简单的方式帮助我。我有搜索量,但我找不到合适的解决方案。这是我的代码。 帮助将不胜感激

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);
            }

        });

    }

1 个答案:

答案 0 :(得分:1)