I have three layout for each activity: layout, layout-large and layout-xlarge to be able to adapt my application to all the screens, the problem is that I use a custom listview with my ListViewAdapter class and its xml, but the xml measures of my ListViewAdapter are not the correct ones in the three layout (large, xlarge) therefore I need to create different xml of my ListViewAdapter, but how do I do for layout-large and xlarge load different xml (of my ListViewAdapter)? I hope you understand my question
I leave my ListViewAdapter here:
public class ListViewAdapter extends BaseAdapter {
// Declare Variables
Context context;
String[] titulos;
int[] imagenes;
LayoutInflater inflater;
public ListViewAdapter(Context context, String[] titulos, int[] imagenes) {
this.context = context;
this.titulos = titulos;
this.imagenes = imagenes;
}
@Override
public int getCount() {
return titulos.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView txtTitle;
ImageView imgImg;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.list_row, parent, false);
// Locate the TextViews in listview_item.xml
txtTitle = (TextView) itemView.findViewById(R.id.list_row_title);
imgImg = (ImageView) itemView.findViewById(R.id.list_row_image);
// Capture position and set to the TextViews
txtTitle.setText(titulos[position]);
imgImg.setImageResource(imagenes[position]);
return itemView;
}
}
my class:
public class cat_recetas extends AppCompatActivity {
ListViewAdapter adapter;
String[] titulo = new String[]{
"Top 15",
};
int[] imagenes = {
R.drawable.icon_top_15,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cat_recetas);
final ListView lista = (ListView) findViewById(R.id.listview_rec);
adapter = new ListViewAdapter(this, titulo, imagenes);
lista.setAdapter(adapter);
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView adapterView, View view, int posicion, long l) {
switch (posicion) {
case 0:
Intent top15 = new Intent(getApplicationContext(), top15.class);
startActivity(top15);
break;
}
}
});
}
}