2013-09-24 48 views
-2

我想在列表視圖中顯示來自mysql數據庫的內容是我的listactivity,我正在執行到我的界面FetchDataListener.But它給錯誤 1.型MainActivity的方法onFetchComplete(列表)必須覆蓋一個超類方法錯誤 型MainActivity的方法2. onFetchFailure(列表)必須覆蓋一個超類方法錯誤MainActivity類型的onFetchComplete(列表<Application>)方法必須重寫超類方法錯誤

請參見下面的類和接口文件

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

請幫助我, 在此先感謝

+0

我沒有看到你導入你的類 – tyczj

+0

你的意思是我需要導入接口在我mainactivity界面? – user2723139

+0

是例如'import com.example.YourClass.FetchDataListener;' – tyczj

回答

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

你在MYSQL你可以解僱查詢(INSERT,UPDATE ,DELETE)使用db.execSQL()

To Retrive數據,您可以使用此

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. 
相關問題