-2

我试图在下面的 listview 中显示 mysql 数据库中的内容是我正在实现到我的接口 FetchDataListener 的 listactivity。但它给出了错误 1.MainActivity 类型的 onFetchComplete(List) 方法必须覆盖超类方法错误 2. MainActivity 类型的方法 onFetchFailure(List) 必须覆盖超类方法错误

请参阅下面的类和接口文件

班级

/*package com.example.androidhive;
import java.util.List;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends ListActivity implements FetchDataListener{
private ProgressDialog dialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);       
    setContentView(R.layout.activity_main);       
    initView();  
}

private void initView() {
    // show progress dialog
    dialog = ProgressDialog.show(this, "", "Loading...");

    String url = "http://192.168.0.2/android_login_api/include/apps.php";
    FetchDataTask task = new FetchDataTask(this);
    task.execute(url);
}

@Override
public void onFetchComplete(List<Application> data) {
    // dismiss the progress dialog
    if(dialog != null)  dialog.dismiss();
    // create new adapter
    ApplicationAdapter adapter = new ApplicationAdapter(this, data);
    // set the adapter to list
    setListAdapter(adapter);       
}

@Override
public void onFetchFailure(String msg) {
    // dismiss the progress dialog
    if(dialog != null)  dialog.dismiss();
    // show failure message
    Toast.makeText(this, msg, Toast.LENGTH_LONG).show();       
}
}
*/

界面

/*package com.example.androidhive;

import java.util.List;

public interface FetchDataListener {
public void onFetchComplete(List<Application> data);

public void onFetchFailure(String msg);
}
*/

请帮助我,在此先感谢

4

1 回答 1

0

为此使用 SQLiteDatabase 类

 SQLiteDatabase db = openOrCreateDatabase("Database_Name", MODE_PRIVATE, null);

 //Create Table 
 String  strsql = "CREATE TABLE IF NOT EXISTS TableName(Name  VARCHAR(30),id    INT(15)  unique) ";
db.execSQL(strsql);       

您可以使用 db.execSQL() 像在 MYSQL(INSERT,UPDATE,DELETE) 中一样触发查询

要检索数据,您可以使用它

 strsql = "SELECT * FROM TableName ";

 Cursor c = db.rawQuery(strsql, null);

    int count = c.getCount();
    c.moveToFirst();

    while (k >= 0) {
              ListviewContent.add(c.getString(c.getColumnIndex("Name")));
        setListAdapter(new ListViewAdapter(this));
        c.moveToNext();
        k--;

    }

 //you can set retrived data to list view as shown above.
于 2013-09-24T18:21:37.467 回答