Урок 136. CursorLoader
Re: Урок 136. CursorLoader
Созрел еще вопрос.
Есть ListView, который формируется из мною определенного Item, состоящего из нескольких TextView.
В одно из этих TextView (id tvComment) выводится комментарий. Комментарий не всегда есть, поэтому tvComment остается пустым и тупо занимает место. Я его убираю (он исчезает и больше не появляется - с этим все нормально), но еще рандомно убираются некоторые tvComment, в которых комментарий есть... Т.е. tvComment пропадет, а после прокрутки вверх/вниз может появиться, но исчезнет другой/другие...
На что обратить внимание или что попробовать сделать?
item.xml:
[syntax=xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvProductName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="@string/item_ProductName"
android:textSize="18sp" >
</TextView>
<TextView
android:id="@+id/tvComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:text="@string/item_Comment"
android:textColor="@color/clAdditionInfo" >
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/tvCatName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:text="@string/item_CatName"
android:textColor="@color/clAdditionInfo" >
</TextView>
<TextView
android:id="@+id/tvQuantityAndMeasure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="@string/item_QuantityAndMeasure"
android:textColor="@color/clAdditionInfo" />
</RelativeLayout>
</LinearLayout>
[/syntax]
Фрагменты кода, в котором убираю пустые вьюшки:
[syntax=java]
.........
ListView lvData;
SimpleCursorAdapter scAdapter;
.........
protected void onCreate(Bundle savedInstanceState) {
.........
scAdapter = new SimpleCursorAdapter(this, R.layout.item, null, from, to, 0);
scAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.tvComment) {
int commentIndex = cursor.getColumnIndex("comment2");
String s = cursor.getString(commentIndex);
TextView textView = (TextView) view;
if (s == null || s.equals("") ) {
textView.setVisibility(View.GONE);
}
else {
textView.setText(s);
}
return true;
}
return false;
}
});
lvData = (ListView) findViewById(R.id.lvMain);
lvData.setAdapter(scAdapter);
........
[/syntax]
Есть ListView, который формируется из мною определенного Item, состоящего из нескольких TextView.
В одно из этих TextView (id tvComment) выводится комментарий. Комментарий не всегда есть, поэтому tvComment остается пустым и тупо занимает место. Я его убираю (он исчезает и больше не появляется - с этим все нормально), но еще рандомно убираются некоторые tvComment, в которых комментарий есть... Т.е. tvComment пропадет, а после прокрутки вверх/вниз может появиться, но исчезнет другой/другие...
На что обратить внимание или что попробовать сделать?
item.xml:
[syntax=xml]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvProductName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="@string/item_ProductName"
android:textSize="18sp" >
</TextView>
<TextView
android:id="@+id/tvComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:text="@string/item_Comment"
android:textColor="@color/clAdditionInfo" >
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/tvCatName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:text="@string/item_CatName"
android:textColor="@color/clAdditionInfo" >
</TextView>
<TextView
android:id="@+id/tvQuantityAndMeasure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="@string/item_QuantityAndMeasure"
android:textColor="@color/clAdditionInfo" />
</RelativeLayout>
</LinearLayout>
[/syntax]
Фрагменты кода, в котором убираю пустые вьюшки:
[syntax=java]
.........
ListView lvData;
SimpleCursorAdapter scAdapter;
.........
protected void onCreate(Bundle savedInstanceState) {
.........
scAdapter = new SimpleCursorAdapter(this, R.layout.item, null, from, to, 0);
scAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.tvComment) {
int commentIndex = cursor.getColumnIndex("comment2");
String s = cursor.getString(commentIndex);
TextView textView = (TextView) view;
if (s == null || s.equals("") ) {
textView.setVisibility(View.GONE);
}
else {
textView.setText(s);
}
return true;
}
return false;
}
});
lvData = (ListView) findViewById(R.id.lvMain);
lvData.setAdapter(scAdapter);
........
[/syntax]
Re: Урок 136. CursorLoader
кто ж так убирает? это все обрабатывать нужно в getView методе адаптера..
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
Нашел такую конструкцию:
[syntax=java]
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
return view;
}
}
[/syntax]
Как в ней обратиться к нужному мне TextView?
[syntax=java]
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
return view;
}
}
[/syntax]
Как в ней обратиться к нужному мне TextView?
Re: Урок 136. CursorLoader
как и из любого другого места - с помощью метода findViewById
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
Я так пробовал, у меня получается то же самое, что и в предыдущей реализации через ViewBinder, т.е. скрываются непустые комментарии.
Делал так:
[syntax=java]
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (convertView != null) {
TextView textview = (TextView) convertView.findViewById(R.id.tvComment);
String s = textview.getText().toString();
if (s == null || s.equals("")) {
textview.setVisibility(View.GONE);
} else {
// textview.setText(s);
}
}
return view;
}
[/syntax]
Делал так:
[syntax=java]
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (convertView != null) {
TextView textview = (TextView) convertView.findViewById(R.id.tvComment);
String s = textview.getText().toString();
if (s == null || s.equals("")) {
textview.setVisibility(View.GONE);
} else {
// textview.setText(s);
}
}
return view;
}
[/syntax]
Re: Урок 136. CursorLoader
вместо этого
String s = textview.getText().toString();
if (s == null || s.equals("")) {
тебе нужно проверять значение в курсоре!
String s = textview.getText().toString();
if (s == null || s.equals("")) {
тебе нужно проверять значение в курсоре!
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
Использую курсор - результат тот же...
[syntax=java]
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (convertView != null) {
TextView textview = (TextView) convertView.findViewById(R.id.tvComment);
Cursor cursor = super.getCursor();
int commentIndex = cursor.getColumnIndex("comment2");
String s = cursor.getString(commentIndex);
if (s == null || s.equals("")) {
textview.setVisibility(View.GONE);
} else {
// textview.setText(s);
}
}
return view;
}
}
[/syntax]
[syntax=java]
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (convertView != null) {
TextView textview = (TextView) convertView.findViewById(R.id.tvComment);
Cursor cursor = super.getCursor();
int commentIndex = cursor.getColumnIndex("comment2");
String s = cursor.getString(commentIndex);
if (s == null || s.equals("")) {
textview.setVisibility(View.GONE);
} else {
// textview.setText(s);
}
}
return view;
}
}
[/syntax]
Re: Урок 136. CursorLoader
сорри, не то.
ты забыл на строчку перейти в курсоре соответствущую.
Cursor mCursor = getCursor();
mCursor.moveToPosition(position);
поэтому он у тебя может на однйо строчке толочься.
ты забыл на строчку перейти в курсоре соответствущую.
Cursor mCursor = getCursor();
mCursor.moveToPosition(position);
поэтому он у тебя может на однйо строчке толочься.
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
Делаю нечто подобное
Адаптер
[syntax=java]public class ScannerListCursorAdapter extends SimpleCursorAdapter implements Filterable {
static final String CATALOG_NAME = "catalogname";
static final String NAME_STATUS = "nstatus";
private int layout;
public ScannerListCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
this.layout = layout;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Cursor c = getCursor();
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
int nameCol = c.getColumnIndex(CATALOG_NAME);
String name = c.getString(nameCol);
int statCol = c.getColumnIndex(NAME_STATUS);
String nameStatCol = c.getString(statCol);
TextView name_text = (TextView) v.findViewById(R.id.tvText);
TextView stat_name_col = (TextView) v.findViewById(R.id.tvTextCol);
if (name_text != null) {
name_text.setText(name);
}
if(stat_name_col != null){
stat_name_col.setText("no");
}
return v;
}
@Override
public void bindView(View v, Context context, Cursor c) {
int nameCol = c.getColumnIndex(CATALOG_NAME);
String name = c.getString(nameCol);
int statCol = c.getColumnIndex(NAME_STATUS);
String nameStatCol = c.getString(statCol);
TextView name_text = (TextView) v.findViewById(R.id.tvText);
TextView stat_name_col = (TextView) v.findViewById(R.id.tvTextCol);
if (name_text != null) {
name_text.setText(name);
}
if(stat_name_col != null){
stat_name_col.setText("sveta");
}
}
}
[/syntax]
В активности
[syntax=java]
String[] from = new String[] { CATALOG_NAME, NAME_STATUS };
adapter = new ScannerListCursorAdapter(this, R.layout.item, null, from, null);
lvData = (ListView) findViewById(R.id.lvData);
lvData.setAdapter(adapter);[/syntax]
Адаптер
[syntax=java]public class ScannerListCursorAdapter extends SimpleCursorAdapter implements Filterable {
static final String CATALOG_NAME = "catalogname";
static final String NAME_STATUS = "nstatus";
private int layout;
public ScannerListCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
this.layout = layout;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Cursor c = getCursor();
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
int nameCol = c.getColumnIndex(CATALOG_NAME);
String name = c.getString(nameCol);
int statCol = c.getColumnIndex(NAME_STATUS);
String nameStatCol = c.getString(statCol);
TextView name_text = (TextView) v.findViewById(R.id.tvText);
TextView stat_name_col = (TextView) v.findViewById(R.id.tvTextCol);
if (name_text != null) {
name_text.setText(name);
}
if(stat_name_col != null){
stat_name_col.setText("no");
}
return v;
}
@Override
public void bindView(View v, Context context, Cursor c) {
int nameCol = c.getColumnIndex(CATALOG_NAME);
String name = c.getString(nameCol);
int statCol = c.getColumnIndex(NAME_STATUS);
String nameStatCol = c.getString(statCol);
TextView name_text = (TextView) v.findViewById(R.id.tvText);
TextView stat_name_col = (TextView) v.findViewById(R.id.tvTextCol);
if (name_text != null) {
name_text.setText(name);
}
if(stat_name_col != null){
stat_name_col.setText("sveta");
}
}
}
[/syntax]
В активности
[syntax=java]
String[] from = new String[] { CATALOG_NAME, NAME_STATUS };
adapter = new ScannerListCursorAdapter(this, R.layout.item, null, from, null);
lvData = (ListView) findViewById(R.id.lvData);
lvData.setAdapter(adapter);[/syntax]
Re: Урок 136. CursorLoader
alexmx, то человек мозгами шевелил, все правильно делал, был на правильном пути.
Теперь скопирует твой код - чему научится?
Теперь скопирует твой код - чему научится?
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
Foenix
В любом случае думать нужно что к чему
В любом случае думать нужно что к чему
Re: Урок 136. CursorLoader
ну не скажи..
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
Я больше так не буду
Re: Урок 136. CursorLoader
Я часто наталкивался на рекомендации использовать newView и bindView вместо getView. Inflater тоже все время меня смущал. Теперь вот использовал всё...
Разобрал пример от alexmx. Сделал все под себя, оказалось, что кроме вьюхи tvComment надо будет всем TextView присваивать значения в этих 2-х методах, но это меня не беспокоит. Беспокоит то, что это ТОЖЕ не помогло скрыть только пустые вью
Все также хаотично то скрывается, то появляется после прокрутки как и в прошлых реализациях...
В логе вижу, что комментарий есть, но вьюха скрывается, а потом после нескольких прокруток туда-сюда появлется! Корректно работает только скрытие действительно там, где комментария нет.
[syntax=java]
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Cursor c = getCursor();
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
int colIndex = c.getColumnIndex("comment2");
String comment = c.getString(colIndex);
Log.d(LOG_TAG, "newView: colIndex = " + colIndex);
TextView textviewComment = (TextView) v.findViewById(R.id.tvComment);
if (textviewComment != null) {
textviewComment.setText(comment);
}
Log.d(LOG_TAG, "newView: comment = " + comment);
return v;
}
@Override
public void bindView(View v, Context context, Cursor c) {
int colIndex = c.getColumnIndex("comment2");
String comment = c.getString(colIndex);
Log.d(LOG_TAG, "bindView: colIndex = " + colIndex);
TextView textviewComment = (TextView) v.findViewById(R.id.tvComment);
if (textviewComment != null) {
if ((comment == null) || (comment.equals(""))) {
textviewComment.setVisibility(View.GONE);
} else {
textviewComment.setText(comment);
}
}
Log.d(LOG_TAG, "bindView: comment = " + comment);
}
[/syntax]
Разобрал пример от alexmx. Сделал все под себя, оказалось, что кроме вьюхи tvComment надо будет всем TextView присваивать значения в этих 2-х методах, но это меня не беспокоит. Беспокоит то, что это ТОЖЕ не помогло скрыть только пустые вью
Все также хаотично то скрывается, то появляется после прокрутки как и в прошлых реализациях...
В логе вижу, что комментарий есть, но вьюха скрывается, а потом после нескольких прокруток туда-сюда появлется! Корректно работает только скрытие действительно там, где комментария нет.
[syntax=java]
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Cursor c = getCursor();
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
int colIndex = c.getColumnIndex("comment2");
String comment = c.getString(colIndex);
Log.d(LOG_TAG, "newView: colIndex = " + colIndex);
TextView textviewComment = (TextView) v.findViewById(R.id.tvComment);
if (textviewComment != null) {
textviewComment.setText(comment);
}
Log.d(LOG_TAG, "newView: comment = " + comment);
return v;
}
@Override
public void bindView(View v, Context context, Cursor c) {
int colIndex = c.getColumnIndex("comment2");
String comment = c.getString(colIndex);
Log.d(LOG_TAG, "bindView: colIndex = " + colIndex);
TextView textviewComment = (TextView) v.findViewById(R.id.tvComment);
if (textviewComment != null) {
if ((comment == null) || (comment.equals(""))) {
textviewComment.setVisibility(View.GONE);
} else {
textviewComment.setText(comment);
}
}
Log.d(LOG_TAG, "bindView: comment = " + comment);
}
[/syntax]
Re: Урок 136. CursorLoader
вот видишь, он на твой код посмотрел (невнимательно) а мое замечание (про курсор) пропустил.alexmx писал(а):Foenix
В любом случае думать нужно что к чему
Что вышло?
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
автор вопроса. Лучше бы ты убрал то, что там у тебя два раза проверяется в одном и другом методе и сделал в одном - правильно.
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
Я это делал. Курсор и так на одном месте не стоял, я видел в логе. Что с moveToPosition что без этого метода результат не поменялся.Foenix писал(а): ты забыл на строчку перейти в курсоре соответствущую.
Cursor mCursor = getCursor();
mCursor.moveToPosition(position);
поэтому он у тебя может на однйо строчке толочься.
А что не так с последним примером не так?
Re: Урок 136. CursorLoader
ну докажи, покажи лог и код соответствующий.Я это делал. Курсор и так на одном месте не стоял, я видел в логе.
все не так. Я уже объяснила.А что не так с последним примером не так?
R.id.team
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
NullPointerException - что делать???
viewtopic.php?f=33&t=3899&p=28952#p28952
Где моя ошибка?
viewtopic.php?f=60&t=3198
Re: Урок 136. CursorLoader
Код с выводом лога:
[syntax=java]
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (convertView != null) {
TextView textview = (TextView) convertView.findViewById(R.id.tvComment);
Cursor cursor = super.getCursor();
int beforePosition = cursor.getPosition();
cursor.moveToPosition(position);
int nowPosition = cursor.getPosition();
Log.d(LOG_TAG, "getView: beforePosition = " + beforePosition + " nowPosition = " + nowPosition);
int commentIndex = cursor.getColumnIndex("comment2");
String s = cursor.getString(commentIndex);
if (s == null || s.equals("")) {
textview.setVisibility(View.GONE);
} else {
textview.setText(s);
}
}
return view;
}
}
}
[/syntax]
Лог после пары прокруток списка:
[syntax=java]
private class MyCursorAdapter extends SimpleCursorAdapter {
public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (convertView != null) {
TextView textview = (TextView) convertView.findViewById(R.id.tvComment);
Cursor cursor = super.getCursor();
int beforePosition = cursor.getPosition();
cursor.moveToPosition(position);
int nowPosition = cursor.getPosition();
Log.d(LOG_TAG, "getView: beforePosition = " + beforePosition + " nowPosition = " + nowPosition);
int commentIndex = cursor.getColumnIndex("comment2");
String s = cursor.getString(commentIndex);
if (s == null || s.equals("")) {
textview.setVisibility(View.GONE);
} else {
textview.setText(s);
}
}
return view;
}
}
}
[/syntax]
Лог после пары прокруток списка:
Код: Выделить всё
03-28 06:10:21.545: D/myLogs(1215): getView: beforePosition = 1 nowPosition = 1
03-28 06:10:21.545: D/myLogs(1215): getView: beforePosition = 2 nowPosition = 2
03-28 06:10:21.555: D/myLogs(1215): getView: beforePosition = 3 nowPosition = 3
03-28 06:10:21.555: D/myLogs(1215): getView: beforePosition = 4 nowPosition = 4
03-28 06:10:21.565: D/myLogs(1215): getView: beforePosition = 5 nowPosition = 5
03-28 06:10:21.565: D/myLogs(1215): getView: beforePosition = 6 nowPosition = 6
03-28 06:10:21.575: D/myLogs(1215): getView: beforePosition = 7 nowPosition = 7
03-28 06:10:21.575: D/myLogs(1215): getView: beforePosition = 0 nowPosition = 0
03-28 06:10:36.756: D/myLogs(1215): getView: beforePosition = 8 nowPosition = 8
03-28 06:10:37.086: D/myLogs(1215): getView: beforePosition = 9 nowPosition = 9
03-28 06:10:38.036: D/myLogs(1215): getView: beforePosition = 10 nowPosition = 10
03-28 06:10:38.156: D/myLogs(1215): getView: beforePosition = 11 nowPosition = 11
03-28 06:10:38.436: D/myLogs(1215): getView: beforePosition = 12 nowPosition = 12
03-28 06:10:39.045: D/myLogs(1215): getView: beforePosition = 13 nowPosition = 13
03-28 06:10:39.156: D/myLogs(1215): getView: beforePosition = 14 nowPosition = 14
03-28 06:10:39.296: D/myLogs(1215): getView: beforePosition = 15 nowPosition = 15
03-28 06:10:39.496: D/myLogs(1215): getView: beforePosition = 16 nowPosition = 16
03-28 06:10:39.756: D/myLogs(1215): getView: beforePosition = 17 nowPosition = 17
03-28 06:10:39.856: D/myLogs(1215): getView: beforePosition = 18 nowPosition = 18
03-28 06:10:39.986: D/myLogs(1215): getView: beforePosition = 19 nowPosition = 19
03-28 06:10:41.146: D/myLogs(1215): getView: beforePosition = 12 nowPosition = 12
03-28 06:10:41.316: D/myLogs(1215): getView: beforePosition = 11 nowPosition = 11
03-28 06:10:41.426: D/myLogs(1215): getView: beforePosition = 10 nowPosition = 10
03-28 06:10:41.516: D/myLogs(1215): getView: beforePosition = 9 nowPosition = 9
03-28 06:10:41.666: D/myLogs(1215): getView: beforePosition = 8 nowPosition = 8
03-28 06:10:41.776: D/myLogs(1215): getView: beforePosition = 7 nowPosition = 7
03-28 06:10:41.866: D/myLogs(1215): getView: beforePosition = 6 nowPosition = 6
03-28 06:10:42.076: D/myLogs(1215): getView: beforePosition = 5 nowPosition = 5
03-28 06:10:42.196: D/myLogs(1215): getView: beforePosition = 4 nowPosition = 4
03-28 06:10:42.435: D/myLogs(1215): getView: beforePosition = 3 nowPosition = 3
03-28 06:10:43.475: D/myLogs(1215): getView: beforePosition = 2 nowPosition = 2
03-28 06:10:43.725: D/myLogs(1215): getView: beforePosition = 1 nowPosition = 1
03-28 06:10:44.155: D/myLogs(1215): getView: beforePosition = 0 nowPosition = 0