Список Просмотр курсадаптер отображает текст, но не изображенияAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Список Просмотр курсадаптер отображает текст, но не изображения

Сообщение Anonymous »

Я делаю представление списка из SQLitedAtabase, принимаю эту информацию и помещаю его в представление списка. База данных работает нормально, но когда я собираюсь поместить информацию о базе данных в компоненты ListView, ресурс изображения не отображается. Текст отображается нормально, но изображения нет. Если бы вы могли помочь, я бы очень признателен!public class ChampCursorAdapter extends CursorAdapter {

private Cursor cursor;
private Context context;
private LayoutInflater inflater;
private final int layoutID = R.layout.champ_list_item_2;

@SuppressWarnings("deprecation")
public ChampCursorAdapter(Context con, Cursor c) {
super(con, c);
context = con;
cursor = c;
inflater = LayoutInflater.from(con);
}

@Override
public void bindView(View view, Context con, Cursor cur) {

// get resources for view objects
TextView name = (TextView) view.findViewById(R.id.name);
TextView title = (TextView) view.findViewById(R.id.title);
ImageView image = (ImageView) view.findViewById(R.id.imageView);

// set name and title
name.setText(cur.getString(cur.getColumnIndex(Champ.COLUMN_CHAMP)));
title.setText(cur.getString(cur.getColumnIndex(Champ.COLUMN_TITLE)));

// set image
String pic = cur.getString(cur.getColumnIndex(Champ.COLUMN_PIC));
BitmapDrawable picture = new BitmapDrawable(con.getResources(),pic);
image.setImageDrawable(picture);
image.setVisibility(ImageView.VISIBLE);

}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = inflater.inflate(layoutID, parent, false);
return v;
}

}
< /code>
Вот элемент списка xml:

< /p>














< /code>
Вот mainActivity.java < /p>
public class MainActivity extends Activity {

private Champ champList;
private ChampCursorAdapter dataAdapter;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

champList = new Champ(MainActivity.this);
champList.open();
champList.removeChamps();
createChamps();
createListView();
champList.close();
}

// other stuff here

// creates the list view object and sets the adapter
private void createListView() {

Cursor cursor = champList.getChamps();

// create the adapter using the cursor pointing to the desired data
// as well as the layout information
dataAdapter = new ChampCursorAdapter(this, cursor);
ListView listview = (ListView) findViewById(R.id.listView);
listview.setAdapter(dataAdapter);
}


Подробнее здесь: https://stackoverflow.com/questions/169 ... not-images
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»