So, i've been trying to develop an app where u order sandwiches by yourself. So far I've managed everything with the listview, what type of sandwiches you can order etc.
Then I move onto the next activity, which is supposed to display the sandwiches the user picked, but unfortunately nothing pops up.
If you have an alternative code for the second activity im open for it.
Code1 = Where you order what sandwich:
package com.example.boo.cafestudent;
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.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class Order extends AppCompatActivity{
ArrayList<String> klickademackor = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.orderactivity);
String[] mackor ={"Ostsmörgås","Skinksmörgås","Ost och Skinksmörgås", "Salamismörgås","Räksmörgås",
"Rensmörgås", "Älgsmörgås", "Köttbullesmörgås"};
ListAdapter johansadapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mackor);
//hämtar ListView
ListView mackorListView = (ListView) findViewById(R.id.ListViewMackor);
//Hämtar data från array stringen
// final String[] array_mackor = getResources().getStringArray(R.array.arraymackor);
//skapandet av en array adapter
//Själva adaptern till ListView
mackorListView.setAdapter(johansadapter);
//kopplar onClicklistener till Listvie
mackorListView.setOnItemClickListener(
new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
String mackor = String.valueOf(parent.getItemAtPosition(position));
Toast.makeText(Order.this, mackor + " har lagts till", Toast.LENGTH_LONG).show();
klickademackor.add(mackor);
}
});
};
public void onClick (View View){
Intent i = new Intent (Order. this, Confirmation.class);
startActivity(i);
}}
Code2 = Supposed to show the results using a textview which ID is textview2.
package com.example.boo.cafestudent;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
public class Confirmation extends AppCompatActivity {
ArrayList<String> klickademackor = new ArrayList<String>();
private TextView textviewMackor;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.confirmationactivity);
textviewMackor = (TextView) findViewById(R.id.textView2);
for (String index : klickademackor) {
textviewMackor.append(index + "\n");
}
}
public void confirmation (View view){
Toast.makeText(this,"Din beställning är bekräftad", Toast.LENGTH_SHORT).show();
}
}