CursorAdapter

Tutorials with advanced 'difficulty' and more Lines of Code.

CursorAdapter

Postby spoorti » Fri Nov 06, 2009 11:21 am

Hi,

I am using CursorAdapter, newView & bindView for displaying the data from the Cursor. But in the UI I am able to see only the first row and rest are getting displayed as false...
Please help me out in solving this

XML
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLAyout" android:orientation="vertical">

<TextView android:text="@+id/TextView01" android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="@+id/TextView02" android:id="@+id/number" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="@+id/TextView03" android:id="@+id/duration" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>

Java

public class test extends TabActivity {

TextView nameView;
TextView numberView;
TextView dateView;
TextView durationView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// all information
Cursor c = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
android.provider.CallLog.Calls.DATE + " DESC");
startManagingCursor(c);
CursorAdapter all = new CursorAdapter(this, c) {

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = ((Activity) context)
.getLayoutInflater();
final View v = inflater.inflate(R.layout.all, parent, false);
Log.e("@@@@@@@@@@@@@@V","View");

// final View view = mInflater.inflate(R.layout.custom_list,
// parent, false);
return v;
}

@Override
public void bindView(View view, Context context, Cursor cursor1) {
// TODO Auto-generated method stub

nameView = (TextView) findViewById(R.id.name);
numberView = (TextView) findViewById(R.id.number);
dateView = (TextView) findViewById(R.id.date);

if (nameView != null) {
int index = cursor1.getColumnIndex(Calls.CACHED_NAME);
String name = cursor1.getString(index);
if(name==null)
name = "default";
Log.e("@@@@@@@@@@@@@@NAme",name);
nameView.setText(name);
}

if (numberView != null) {
int index = cursor1.getColumnIndex(Calls.NUMBER);
String number = cursor1.getString(index);
if(number==null)
number = "default";
Log.e("@@@@@@@@@@@@@@Number",number);
numberView.setText(number);
}

if (dateView != null) {

int flags = DateUtils.FORMAT_ABBREV_RELATIVE;
// long data =
// cursor1.getLong(cursor1.getColumnIndex(Calls.DATE));
String str = DateUtils
.getRelativeTimeSpanString(
cursor1.getLong(cursor1
.getColumnIndex(Calls.DATE)),
System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS, flags)
.toString();
if(str==null)
str = "default";
Log.e("@@@@@@@@@@@@@@Date",str);
dateView.setText(str);
}

durationView = (TextView) findViewById(R.id.duration);
if (durationView != null) {
int index = cursor1.getColumnIndex(Calls.DURATION);
long duration = cursor1.getLong(index);

String test = cursor1.getString(index);

Log.e("@@@@@@@@@@@@@@duration",test);
durationView.setText(formatDuration(duration));
}

// cursor1.moveToNext();
// }
}
};
}

Please Tel me what the problem might be
spoorti
Junior Developer
Junior Developer
 
Posts: 12
Joined: Mon Jul 06, 2009 6:36 am

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests