@SuppressWarnings("deprecation")
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
MainActivity.this, R.layout.user, cursor, from, to)
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
cursor.moveToPosition(position);
String s = cursor.getString(cursor.getColumnIndex("USER_SEX"));
final View row = super.getView(position, convertView, parent);
LayoutInflater inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View sexxx = inflater.inflate(R.layout.user, null);
sexlogo = (ImageView) sexxx.findViewById(R.id.sex);
if (s.equalsIgnoreCase("Male"))
sexlogo.setImageResource(R.drawable.male);
else
sexlogo.setImageResource(R.drawable.female);
return row;
}
};
am new to Android, the app adds a user to SQLite databse
then retrieves all users found in the database to a ListView
using a cursor
.
i want to check user's sex and then set him a logo after retrieving his data from database and before adding him to the listView
.
i have edited my question and added the code above, the app didn't crash moreover images didn't appear .
any help please
this is the correct answer , just remove LayoutInflater
since the super
already inflates it .
inflating a layout
will return a new root
representing the xml
{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
cursor.moveToPosition(position);
String s = cursor.getString(cursor.getColumnIndex("USER_SEX"));
final View row = super.getView(position, convertView, parent);
sexlogo = (ImageView) row.findViewById(R.id.sex);
if (s.equals("Male"))
sexlogo.setImageResource(R.drawable.male);
else
sexlogo.setImageResource(R.drawable.female);
return row;
}
};