jeudi 27 août 2015

change card layout based on object type

I am using a card layout to display a list.I have a fragment in which I am displaying the list. I have a image of circle in card view. I want to change the image from small to big based on card type. For that I have created two card layout in which circle image size differs. I have created two different adapters respectively. I have a class Expense in which I have a object of expenseType based on this type I want to change card layouts. How can i achieve this????

Help will be appreciated...Thank You..

Class code

 public class Expense {

    String amount;
    String expense;
    public int expenseType;

Expense(){}
    Expense(String amount,String expense,int expenseType)
    {
        this.amount=amount;
        this.expense=expense;
        this.expenseType=expenseType;
    }

    public void setExpenseType(int expenseType)
    {
        this.expenseType=expenseType;
    }
    public int getExpenseType()
    {
        return expenseType;
    }

}

Fragment code

public class ItemFragment extends Fragment {
    ArrayList<Expense> items=new ArrayList<Expense>();

    RecyclerView recyclerView;
    public ItemFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_item_list, container, false);

        Expense e=new Expense();

        recyclerView=(RecyclerView)view.findViewById(R.id.RecyclerView);
        ImageButton imageButton = (ImageButton)view.findViewById(R.id.imgbtn_fab);
        LinearLayoutManager llm = new LinearLayoutManager(this.getActivity());
        recyclerView.setLayoutManager(llm);

        recyclerView.setHasFixedSize(true);

        initializeDataType1();
        int type= e.getExpenseType();



            ItemAdapter adapter = new ItemAdapter(items);
            recyclerView.setAdapter(adapter);



          //  bigCircleAdapter ad = new bigCircleAdapter(items);
            //recyclerView.setAdapter(ad);



        return view;

    }

    private void initializeDataType1() {

        items = new ArrayList<>();
        items.add(new Expense("1000", "2000", 1));
        items.add(new Expense("2000", "5000", 1));
        items.add(new Expense("3000", "400", 2));
        items.add(new Expense("1000", "4000", 1));
        items.add(new Expense("3000", "3000", 2));
        items.add(new Expense("2000", "100", 1));
        items.add(new Expense("2000", "3333", 2));
        items.add(new Expense("3000", "shopping", 1));
        items.add(new Expense("1000", "food", 1));
        items.add(new Expense("1000", "food", 2));
        items.add(new Expense("2000", "drink", 1));
        items.add(new Expense("3000", "shopping", 2));
        items.add(new Expense("2000", "3333", 1));
        items.add(new Expense("3000", "shopping", 1));
        items.add(new Expense("1000", "food", 1));
        items.add(new Expense("1000", "food", 1));
        items.add(new Expense("2000", "drink", 1));
        items.add(new Expense("3000", "shopping", 1));
    }
}

I have inserted dummy data in list. Based on the expenseType object i want to change the layout. I am new to java and android. can anybody help plz... Thank You...

Aucun commentaire:

Enregistrer un commentaire