Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package se.molk.feedme;
- import android.app.ActionBar;
- import android.app.Activity;
- import android.graphics.Color;
- import android.graphics.drawable.ColorDrawable;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.ListView;
- import com.cengalabs.flatui.FlatUI;
- import com.cengalabs.flatui.views.FlatButton;
- import java.util.ArrayList;
- public class MainActivity extends Activity {
- public ArrayList<Integer> backgrounds = new ArrayList<Integer>();
- ListView listView; // Själva listan, den som visas i appen
- ArrayList<String> ingredients = new ArrayList<String>(); // Här inne hamnar alla ingredienser
- ArrayAdapter<String> ingredientsAdapter; // Den här saken länkar ovanstående två saker
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ActionBar bar = getActionBar();
- bar.setBackgroundDrawable(new ColorDrawable(Color.rgb(192, 57, 43)));
- backgrounds.add(FlatUI.SAND);
- backgrounds.add(FlatUI.ORANGE);
- backgrounds.add(FlatUI.CANDY);
- backgrounds.add(FlatUI.BLOSSOM);
- backgrounds.add(FlatUI.GRAPE);
- // backgrounds.add(FlatUI.DEEP);
- backgrounds.add(FlatUI.SKY);
- backgrounds.add(FlatUI.GRASS);
- // backgrounds.add(FlatUI.DARK);
- // backgrounds.add(FlatUI.SNOW);
- backgrounds.add(FlatUI.SEA);
- // backgrounds.add(FlatUI.BLOOD);
- Button butt = (Button) findViewById(R.id.goButton);
- butt.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- backgrounds.add(backgrounds.get(0));
- backgrounds.remove(0);
- // Collections.shuffle(backgrounds);
- FlatButton butt = (FlatButton) findViewById(R.id.goButton);
- butt.getAttributes().setTheme(backgrounds.get(0), getResources());
- }
- });
- listView = (ListView) findViewById(R.id.listView);
- ingredientsAdapter = new ArrayAdapter<String>(
- this, // Kontexten, vetefan vad det är egentligen men det är samma som om man kör getApplicationContext()
- R.layout.list_item_ingredient, // Layouten för en rad/item
- R.id.label, // ID på elementet ingrediensen ska visas på
- ingredients // Arrayen vi samlar alla ingredienser i
- );
- listView.setAdapter(ingredientsAdapter);
- // Klicka på något i listan = ta bort den
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- ingredients.remove(position);
- ingredientsAdapter.notifyDataSetChanged();
- }
- });
- addIngredient("Bröd");
- addIngredient("Smör");
- addIngredient("Ost");
- addIngredient("Brödsmulor");
- addIngredient("Rakblad");
- addIngredient("Tårar");
- addIngredient("Tårar");
- addIngredient("Tårar");
- addIngredient("Tårar");
- addIngredient("Tårar");
- // Nästa steg... fixa så man får ut vad man skrivit när man trycker på + (eller enter)
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- public void addIngredient(String name) {
- ingredients.add(name);
- ingredientsAdapter.notifyDataSetChanged();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement