我希望在2个不同的活动中拥有相同的列表视图(具有相同的字段)。在一个Activity中,每个项目,我想显示2个按钮,而在另一个活动中,我不想显示这些按钮。
有谁知道如何修改我的适配器代码才能获得它? (要构建我的listview,我正在使用适配器)。
public class MyAdapter extends BaseAdapter implements ListAdapter{
(...)
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
DatabaseHelper databaseHelper = new DatabaseHelper(context);
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.mes_info, null);
}
String quantia=String.valueOf(list.get(position).getQuantia());
TextView listItemText = (TextView)view.findViewById(R.id.textViewNome);
listItemText.setText(list.get(position).getNome());
TextView listItemText2 = (TextView)view.findViewById(R.id.textViewQuantia);
listItemText2.setText(quantia+" €");
TextView listItemText3 = (TextView)view.findViewById(R.id.textViewCategoria);
listItemText3.setText(list.get(position).getCategoria());
//Handle buttons and add onClickListeners
ImageButton deleteBtn = (ImageButton)view.findViewById(R.id.ImgButtonDel);
ImageButton editBtn = (ImageButton)view.findViewById(R.id.ImgButtonEdit);
deleteBtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//do something
(...)
}