Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.gui_shopping_list;
- import java.util.ArrayList;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.*;
- import android.widget.AdapterView.OnItemClickListener;
- import android.view.View;
- import android.content.Intent;
- public class HomeActivity extends Activity implements View.OnClickListener
- {
- public final static String PAR_KEY = "com.example.gui_shopping_list.par";
- private Button viewList;
- private ListView listView1;
- public ArrayList<Product> arrayList;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.home);
- Bundle intentExtras = getIntent().getExtras();
- if (intentExtras == null)
- {
- return;
- }
- String name = intentExtras.getString("name");
- String budget = intentExtras.getString("budget");
- //String email = intentExtras.getString("email");
- TextView nameText = (TextView) findViewById(R.id.nameText);
- nameText.setText("Feel free to add items to the basket, " + name + "!");
- TextView budgetText = (TextView) findViewById(R.id.budgetText);
- budgetText.setText("Budget: €" + budget);
- //TextView emailText = (TextView) findViewById(R.id.emailText);
- //emailText.setText(email);
- viewList=(Button)findViewById(R.id.viewList);
- viewList.setOnClickListener(this);
- final Product data[] = new Product[]
- {
- new Product("Bread","Brennans", "1.99"),
- new Product("Milk","Avonmore", "1.49"),
- new Product("Cheese","Dubliner", "2.99"),
- new Product("Eggs","Free Range", "1.79"),
- new Product("Ham","Dennys", "1.29")
- };
- CustomAdapter adapter = new CustomAdapter(this,
- R.layout.listview_item_row, data);
- listView1 = (ListView)findViewById(R.id.listView1);
- listView1.setAdapter(adapter);
- listView1.setOnItemClickListener(new OnItemClickListener()
- {
- public void onItemClick(AdapterView<?> parent, View view, int position,
- long id)
- {
- Toast.makeText(getApplicationContext(),"Item added to list", Toast.LENGTH_LONG).show();
- arrayList.add(data[position]);
- //Intent listIntent = new Intent(HomeActivity.this, ListActivity.class);
- //listIntent.putExtra(data.get(position), data.toString());
- Intent mIntent = new Intent(HomeActivity.this,ListActivity.class);
- Bundle mBundle = new Bundle();
- mBundle.putParcelableArrayList(PAR_KEY, arrayList);
- mIntent.putExtras(mBundle);
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.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();
- if (id == R.id.action_settings)
- {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @Override
- public void onClick(View v)
- {
- // TODO Auto-generated method stub
- Intent intent = new Intent(HomeActivity.this, ListActivity.class);
- startActivity(intent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement