Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView: Can't add sms/inbox items to ListView using cursor
    primarykey
    data
    text
    <p>I am trying to call "body" and "address" from content://sms/inbox and add them to a ListView.</p> <p>"address" going to the Item1 in the ListView, "body" going to SubItem in same ListView.</p> <p>To do this, I am implementing a Cursor to add these items to the ListView.</p> <p>When running the code how I have it now, I get no errors or crashes, but there is nothing added to my ListView at all. I have all of the permissions needed in the manifest.</p> <p>Not sure where I went wrong :( But thanks in advance!</p> <p>My XML layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/header__root" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/black" android:orientation="vertical" &gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/burntorange" android:orientation="horizontal" &gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="147dp" android:layout_height="wrap_content" android:layout_weight="0.13" android:background="@color/burntorange" android:padding="10dp" android:text="Messages" android:textSize="20dp" /&gt; &lt;Button android:id="@+id/bNewMessage" android:layout_width="120dp" android:layout_height="35dp" android:layout_gravity="center" android:layout_margin="4dp" android:background="@color/gray" android:gravity="center" android:onClick="handleClick" android:padding="4dp" android:text="New Thread" android:textColor="@color/white" android:textSize="15dp" /&gt; &lt;/LinearLayout&gt; &lt;ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; </code></pre> <p>My Menu.java:</p> <pre><code>public class Menu extends ListActivity { ListView itemList; @SuppressWarnings("deprecation") @Override public void onCreate(Bundle biscuits) { super.onCreate(biscuits); setContentView(R.layout.header); itemList = (ListView) findViewById(android.R.id.list); Uri uri = Uri.parse("content://sms/inbox"); Cursor c = getContentResolver().query(uri, null, null, null, null); startManagingCursor(c); String[] number = new String [c.getCount()]; String[] body = new String [c.getCount()]; if(c.moveToFirst()){ for (int i=0; i&lt;c.getCount();i++) { body[i]=c.getString(c.getColumnIndexOrThrow("body")).toString(); number[i] =c.getString(c.getColumnIndexOrThrow("address")).toString(); c.moveToNext(); List&lt;Map&lt;String, String&gt;&gt; data = new ArrayList&lt;Map&lt;String, String&gt;&gt;(); Map&lt;String, String&gt; datum = new HashMap&lt;String, String&gt;(2); datum.put("contactNumber", number[i]); datum.put("messagePreview", body[i]); SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_1, new String[] {"contactNumber", "messagePreview"}, new int [] {android.R.id.text1, android.R.id.text2}); itemList.setAdapter(adapter); } } } public void handleClick(View v) { Intent intent = new Intent(); intent.setClass(this, TextActivity.class); startActivity(intent); } protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); String cheese = (String) l.getItemAtPosition(position); Toast.makeText(this, cheese + " Selected", Toast.LENGTH_SHORT).show(); try { Class ourClass = Class.forName("com.example.mytexts." + cheese); Intent ourIntent = new Intent(Menu.this, ourClass); startActivity(ourIntent); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload