1
你好,我想創建應用女巫顯示我在ListView短信,但我不知道我怎麼可以填充listview數據。我試過這樣做,但它不工作。可以檢查我的源代碼和給我一些解決辦法?由於短信收件箱 - ListView
的源代碼:
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Mynewtwo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView list = (ListView) findViewById(R.id.list);
List<String> msgList = getSMS();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.main, msgList);
list.setAdapter(adapter);
}
public List<String> getSMS(){
List<String> sms = new ArrayList<String>();
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);
while (cur.moveToNext()) {
String address = cur.getString(cur.getColumnIndex("address"));
String body = cur.getString(cur.getColumnIndexOrThrow("body"));
sms.add("Number: " + address + " .Message: " + body);
}
return sms;
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
你爲什麼問同樣的問題3倍? http://stackoverflow.com/questions/4905736/sms-inbox-textview和http://stackoverflow.com/questions/4897004/sms-inbox-listview – 2011-02-05 08:51:18
這是另一個源代碼,他們在說我,我必須做出新的話題.. – Adam 2011-02-05 08:57:14