Hi,
I am having some problems trying to extend the SimpleCursorAdapter,
the problem I am trying to solve is simple. I have the 'id' of an SMS
message and I want to associate this with the Name of the person who
sent it (if in the contact-book).
Basically I want to get the current cursor position , check if the
name exists and if so associate it with and @id tag in my layout.
The activity calls the extended cursor as follows:
===================================
String[] columns = new String[] { SMSConstants.ADDRESS,
SMSConstants.BODY};
int[] names = new int[] { R.id.subject, R.id.message };
Cursor c = getSMSCursor();
startManagingCursor(c);
SMSCursorAdaptor myAdapter = new SMSCursorAdaptor(this,
R.layout.table, c, columns, names);
setListAdapter(myAdapter);
The extended Cursor Class is defined as:
===================================
public class SMSCursorAdaptor extends SimpleCursorAdapter {
private Cursor c;
private Context context;
private int layout;
public SMSCursorAdaptor(Context context, int layout, Cursor c, String
[] from, int[] to) {
super(context, layout, c, from, to);
this.c = c;
this.context = context;
this.layout = layout;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
/* Get the current Cursor */
Cursor cursor = getCursor();
/* Know the context */
ContentResolver cr = context.getContentResolver();
LayoutInflater inflate = LayoutInflater.from(context);
View v = inflate.inflate(layout, parent);
/* get the text view */
TextView textView = (TextView) v.findViewById(R.id.row_entry);
/* Now get the id number of the person */
int id = this.c.getColumnIndex("person");
/* Connection string to the DB */
Uri uri = ContentUris.withAppendedId(People.CONTENT_URI,
this.c.getLong(id));
/* Make the query */
Cursor person_cursor = cr.query(uri, null, null, null, null);
int idx = person_cursor.getColumnIndex(People.DISPLAY_NAME);
//String nameValue = person_cursor.getString(idx);
v.setId(idx);
return v;
}
}
Basically I am not sure how to set-up the textView so that it gets the
correct DISPLAY_NAME from the db and outputs it to the @id tag ...
No matter what I have tried I get an IndexOutOfBoundsException
04-18 13:06:19.675: ERROR/AndroidRuntime(252):
android.database.CursorIndexOutOfBoundsException: Index -1 requested,
with a size of 1
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.database.AbstractCursor.checkPosition(AbstractCursor.java:559)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.database.AbstractWindowedCursor.checkPosition
(AbstractWindowedCursor.java:172)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.database.AbstractWindowedCursor.getString
(AbstractWindowedCursor.java:41)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.database.CursorWrapper.getString(CursorWrapper.java:135)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
com.zoomsms.android.util.SMSCursorAdaptor.bindView
(SMSCursorAdaptor.java:51)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.CursorAdapter.getView(CursorAdapter.java:186)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.AbsListView.obtainView(AbsListView.java:1075)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.ListView.measureHeightOfChildren(ListView.java:1107)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.ListView.onMeasure(ListView.java:1051)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.View.measure(View.java:6744)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:
890)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.LinearLayout.measureVertical(LinearLayout.java:347)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.LinearLayout.onMeasure(LinearLayout.java:275)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.View.measure(View.java:6744)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.FrameLayout.onMeasure(FrameLayout.java:208)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.View.measure(View.java:6744)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.LinearLayout.measureVertical(LinearLayout.java:461)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.LinearLayout.onMeasure(LinearLayout.java:275)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.View.measure(View.java:6744)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.widget.FrameLayout.onMeasure(FrameLayout.java:208)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.View.measure(View.java:6744)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.ViewRoot.performTraversals(ViewRoot.java:620)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1103)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.os.Handler.dispatchMessage(Handler.java:88)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.os.Looper.loop(Looper.java:123)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
android.app.ActivityThread.main(ActivityThread.java:3739)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
java.lang.reflect.Method.invokeNative(Native Method)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
java.lang.reflect.Method.invoke(Method.java:515)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:739)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
04-18 13:06:19.675: ERROR/AndroidRuntime(252): at
dalvik.system.NativeStart.main(Native Method)
Help appreciated !!!
-Avron
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---