Adam
- Forum posts: 1
Feb 2, 2011, 7:31:49 PM via Website
Feb 2, 2011 7:31:49 PM via Website
Hello i have a problem with this aplication.
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.telephony.SmsManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
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 file:
<?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>
Error:
Description Resource Path Location Type
list_item cannot be resolved or is not a field Smsfive.java /Sms5/src/sms/five line 30 Java Problem
What can i do please?
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.telephony.SmsManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
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 file:
<?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>
Error:
Description Resource Path Location Type
list_item cannot be resolved or is not a field Smsfive.java /Sms5/src/sms/five line 30 Java Problem
What can i do please?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.