我对此应用程序有疑问。
public class Smsfive extends Activity {
/** Called when the activity is first created.
* @param messages */
public void onCreate(Bundle savedInstanceState, ListView messages) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView list = (ListView) findViewById(R.id.list);
List<String> msgList = getSMS();
for(int i = 0; i<msgList.size(); i++) {
System.out.println(msgList.get(i));
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.list,msgList); --> there is error (R.layout.list_item)
//ListView messages;
messages.setAdapter(adapter);
messages.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
SmsManager m = SmsManager.getDefault();
TextView view;
String destinationNumber=(String) ((TextView) view).getText();
m.sendTextMessage(destinationNumber, null, destinationNumber, null, null);
}
});
}
public List<String> getSMS() {
List<String> messages = new ArrayList<String>();
Uri uri = Uri.parse("content://sms/inbox");
Cursor c = null;
try{
c = getApplicationContext().getContentResolver().query (uri, null, null ,null,null);
}catch(Exception e){
e.printStackTrace();
}
try{
for (boolean hasData = c.moveToFirst(); hasData; hasData = c.moveToNext()) {
final String address = c.getString(c.getColumnIndex("address"));
final String body = c.getString(c.getColumnIndexOrThrow("body"));
messages.add("Number: " + address + ". Message: " + body);
}
}catch(Exception e){
e.printStackTrace();
}
c.close();
return messages;
}
}
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidrientation="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>
错误说明:
资源路径位置类型list_item 无法解决或不是一个领域 Smsfive.java / Sms5 / src / sms /五行 30 Java问题
我能做什么?