Hi, having a little problem, would appreciate some help
The startActivity just doesn't want to open the new intent. I have a toast message and if I comment the startActivity line out, it shows the toast just on the first list item, so it gets the listitem, but it just doesn't want to open the activity. Just crashes the app.
Here is my code:
The startActivity just doesn't want to open the new intent. I have a toast message and if I comment the startActivity line out, it shows the toast just on the first list item, so it gets the listitem, but it just doesn't want to open the activity. Just crashes the app.
Here is my code:
Code:
package com.example.android.sab;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import static android.media.CamcorderProfile.get;
public class brands extends AppCompatActivity {
[USER=1021285]@override[/USER]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.brand_list);
setTitle("Order By Brand");
final ArrayList<Brand> brands = new ArrayList<Brand>();
brands.add(new Brand("Black Label",R.drawable.black_label,R.color.black_label));
brands.add(new Brand("Castle Lager", R.drawable.castle_lager,R.color.castle_lager));
brands.add(new Brand("Castle Lite",R.drawable.castle_lite,R.color.castle_lite));
brands.add(new Brand("Castle Milk Stout",R.drawable.milk_stout,R.color.castle_milk_stout));
brands.add(new Brand("Hansa Pilsner",R.drawable.hansa,R.color.hansa));
brands.add(new Brand("Flying Fish",R.drawable.flying_fish,R.color.flying_fish));
brands.add(new Brand("Lion Lager",R.drawable.lion_lager,R.color.lion_lager));
brands.add(new Brand("Redd's",R.drawable.redds,R.color.redds));
brands.add(new Brand("Brutal Fruit",R.drawable.brutal_fruit,R.color.brutal_fruit));
BrandAdapter adapter = new BrandAdapter(this, brands, R.color.order_by_brand);
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
[USER=1021285]@override[/USER]
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
int itemPosition = position;
switch(itemPosition) {
case 0 :Intent blackLabelIntent = new Intent(brands.this, black_label.class);
startActivity(blackLabelIntent);
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
break;
}}}
);
}}
Last edited by a moderator: