1. Are you ready for the Galaxy S20? Here is everything we know so far!

SMS app

Discussion in 'Android Development' started by Vongrad, Feb 2, 2011.

  1. Vongrad

    Vongrad Lurker
    Thread Starter

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

    //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"
    android:eek:rientation="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?
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Tapirboy

    Tapirboy Newbie

    Double check that you have a list_item.xml in your res/layout folder. Looks like it could be missing or contain corrupt xml..
     
Loading...
Similar Threads - SMS app
  1. kevinmac1
    Replies:
    1
    Views:
    673
  2. Inked
    Replies:
    3
    Views:
    802
  3. aparkin
    Replies:
    5
    Views:
    1,648
  4. dorlow
    Replies:
    18
    Views:
    1,269
  5. netsense
    Replies:
    1
    Views:
    2,513
  6. App Update
    Replies:
    0
    Views:
    757
  7. App Update
    Replies:
    0
    Views:
    1,051
  8. App Update
    Replies:
    0
    Views:
    747
  9. dorlow
    Replies:
    3
    Views:
    2,067
  10. App Update
    Replies:
    0
    Views:
    1,037

Share This Page

Loading...