Reputation: 159
I have in my app a ListView
with adapter
, I use this to show a list with a chechbox
and a textView
public class MyListAdapter extends ArrayAdapter<Model> {
private LayoutInflater inflater;
private int position;
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public MyListAdapter (Context context, List<Model> listMeasurement){
super(context, R.layout.simplerow, R.id.empty, listMeasurement);
inflater= LayoutInflater.from(context);
}
public View getView(int position, View convertView, ViewGroup parent){
Model model= (Model)this.getItem(position);
CheckBox checkBox;
TextView textView;
}
}
My question is:
I want to show another list
in another activity
, this will have an image
, two textViews
and a button
. The image depends on the value of the textView
.
The best way to do this is do other ArrayAdapter
? or use other things?
Thanks in advance.
Upvotes: 0
Views: 1080
Reputation: 6794
You need to extend the BaseAdapter
and override the getView()
method. Here is a sample.
private class CustomAdapter extends BaseAdapter {
private LayoutInflater inflater;
private ArrayList<Model> list;
public CustomAdapter(Context context, ArrayList<Model> list) {
this.inflater = LayoutInflater.from(context);
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
// If the view is null inflate it from xml
if (view == null)
view = inflater.inflate(R.layout.list_row, null);
// Bind xml to java
ImageView icon = (ImageView) view
.findViewById(R.id.image);
TextView text = (TextView) view.findViewById(R.id.text);
text.setText(list.get(position).getText());
icon.setImageDrawable(list.get(position).getDrawable());
return view;
}
}
Upvotes: 1