我一直在尝试将listview数据传递给MySQL数据库,但我不确定如何传递数据。我已经尝试了几个星期,但没有运气所以删除了东西,并希望重新开始,但不知道如何做到这一点 这是我的ListActivity代码.... 如果有人能帮助我,我会很感激吗?我想使用php脚本连接到MySQL,但我不介意是否有人可以提供更简单的连接数据库的解决方案
由于
import java.util.ArrayList;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
ListView lv=(ListView)findViewById(R.id.SmsList);
if(fetchInbox()!=null){
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,fetchInbox());
lv.setAdapter(adapter);
}
}
public ArrayList<String> fetchInbox(){
// Displays in array and grabs the sms from the sms folder and display them on the list view
ArrayList<String> sms=new ArrayList<String>();
// sms folder location
Uri uriSms=Uri.parse("content://sms/");
// created string for id, address ,date, body
Cursor cursor=getContentResolver().query(uriSms, new String[]{"_id","address","date","body"}, null, null, null);
cursor.moveToFirst();
while(cursor.moveToNext()){
// requires number and a message
String address=cursor.getString(1);
String body=cursor.getString(3);
// displays Number : 5556/5554 and Message: any user messages.
sms.add("Number: " +address+"\n Message: " +body);
}
return sms;
}
}