Выполнение нескольких R & D для моей компании. Мы пытаемся иметь listView, который содержит изображение, и два поля для каждой записи в списке.Добавление группы представлений в ListView?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:isScrollContainer="true"
android:focusableInTouchMode="false"
android:focusable="false">
<ImageView android:id="@+id/imgView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="100dp"
android:maxHeight="100dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText android:id="@+id/img_title"
android:hint="Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="150dp"/>
<EditText android:id="@+id/img_desc"
android:hint="Description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="150dp"/>
</LinearLayout>
</LinearLayout>
Это файл макета, который я пытаюсь использовать для элемента, который будет находиться в списке. Внутри getView нашего ImageAdapter (который расширяет ArrayAdapter), Я пытаюсь использовать LayoutInflater для раздувания xml, который я затем храню в ViewGroup. Я findViewByID(), чтобы получить imageView в xml, и установить свойства imageView, которые мы хотели бы.
Если мы продолжаем раздувать этот XML-файл, все идентификаторы будут одинаковыми. Вот наши проблемы.
- Если удалить элемент списка с контекстным меню , он фактически удаляет неправильные один. Тестирование показывает , что в основном последний добавлен, , но не всегда.
- EditText не реагирует на ввод с клавиатуры. Иногда они хранят некоторые данные, обычно всегда «bbb».
У нас больше проблем, но мы опубликуем их после того, как мы зафиксируем эти более серьезные ошибки.
public View getView(int position, View convertView, ViewGroup parent)
{
final ImageView imageView;
//InputStream is = null;
final Context mContext = super.getContext();
final AdapterItem item = super.getItem(position);
final Uri imageUri = item.getUri();
ViewGroup viewGroup = null;
try
{
//-- If the view has not been created yet.
if (convertView == null)
{
/*
* Build the ImageView from the URI with some custom
* view settings.
*/
viewGroup = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.mediauploadobject, null);
imageView = (ImageView) viewGroup.findViewById(R.id.imgView);
//imageView.setLayoutParams(new GridView.LayoutParams(IMAGE_WIDTH, IMAGE_HEIGHT));
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setPadding(IMAGE_PADDING_LEFT, IMAGE_PADDING_TOP,
IMAGE_PADDING_RIGHT, IMAGE_PADDING_BOTTOM);
imageView.setDrawingCacheEnabled(true);
imageView.setClickable(true);
imageView.setFocusable(true);
imageView.setFocusableInTouchMode(true);
imageView.setSaveEnabled(false);
//the following two lines are required for the menu to popUp
imageView.setOnLongClickListener(new LongClickListener());
imageView.setOnCreateContextMenuListener(new LongClickMenu());
imageView.setOnClickListener(new ShortClickListener());
//the following two lines are required to put a boarder around the images
imageView.setOnTouchListener(new PictureOnTouchListener());
imageView.setOnFocusChangeListener(new PictureOnFocusChangeListener());
//-- Keep a reference to the ImageView by tagging it.
imageView.setTag(imageUri);
}else
{
//-- R-E-C-Y-C-L-E recycle!
viewGroup = (ViewGroup) convertView;
imageView = (ImageView) viewGroup.findViewById(R.id.imgView);
}
//-- Lazy load the images so the user doesn't have to wait for all of the querying non-sense
// that happens behind the scenes.
imageView.setImageResource(android.R.drawable.gallery_thumb);
imageView.post(new ImageLoader(imageUri, imageView));
//-- Be VERY careful when changing this code. Due to heap size issues,
// the size of the bitmap image MUST be modified with the
// provided BitmapFactory.Options or the program will
// crash often and frequent.
//post
//-- AJG 7/1/2010 added this assignment so we aren't always setting these preferences every
// iteration
convertView = viewGroup;
}catch(Throwable t)
{
Log.e(TAG, t.toString());
return null;
}finally
{
//try{if(is != null)is.close();}catch(Exception squish){}
}
return viewGroup;
}
Можете ли вы опубликовать код для вашего адаптера. –
Если проблема с удалением элементов, код, который вы используете для удаления элементов, может помочь получить ответ. Не имеет значения, что идентификаторы одинаковы, поскольку каждый элемент в списке будет иметь уникальную позицию в списке (это то, что вы хотели бы использовать для удаления определенного элемента). – kiswa
Я исправил ошибку удаления. Код адаптера составляет около 450 строк. Я собираюсь предположить, что вы скорее увидите часть кода getView. Отредактировано мое оригинальное сообщение с кодом. – DavidAndroidDev