Я хочу, чтобы все Предметы отправлялись в различные действия.Таким образом, Pizza Asterix перейдет к «Pizza_Asterix.xml».
Например, к элементу «Pizza Asterix»
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Asterix", "€7,00", "Tomatensaus, kaas en ananas"));
Когда вы щелкнете по этому элементу, он перейдет в другое действие
Но я не знаю с чего начать.И каждое видео на YouTube использует другую кодировку.Пожалуйста, помогите мне ... Спасибо заранее.(Я действительно новичок в кодировании приложения)
Menu.java
package com.opzet.pizzaria.opzet;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import java.util.ArrayList;
public class Menu extends AppCompatActivity implements ExampleAdapter.OnItemClickListner{
private ArrayList<ExampleItem> mExampleList;
public static final String GERECHT = "ImageView";
public static final String EXTRA_URL = "Text1";
public static final String EXTRA_CREATOR = "Text2";
public static final String EXTRA_LIKES = "Text3";
private RecyclerView mRecyclerView;
private ExampleAdapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
Button show;
Dialog MyDialog;
Button close,kinder,voor,salades,soepen,diversen,pasta,alles,pizza,penette,ravioli,oven,rijst,vlees,vis,afronden;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
show = (Button)findViewById(R.id.show);
show.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view){
MyCustomAlertDialog();
}
});
afronden = (Button)findViewById(R.id.afronden);
afronden.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openAfronden();
}
});
createExampleList();
EditText editText = findViewById(R.id.edittext);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
filter(s.toString());
}
});
}
private void filter(String text) {
ArrayList<ExampleItem> filteredList = new ArrayList<>();
for (ExampleItem item : mExampleList) {
if (item.getText1().toLowerCase().contains(text.toLowerCase())) {
filteredList.add(item);
}
}
for (ExampleItem item : mExampleList) {
if (item.getText3().toLowerCase().contains(text.toLowerCase())) {
filteredList.add(item);
}
}
for (ExampleItem item : mExampleList) {
if (item.getText2().toLowerCase().contains(text.toLowerCase())) {
filteredList.add(item);
}
}
mAdapter.filterList(filteredList);
}
private void createExampleList() {
mExampleList = new ArrayList<>();
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Asterix", "€7,00", "Tomatensaus, kaas en ananas"));
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Obelix", "€7,00", "Tomatensaus, kaas en jam"));
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Idefix", "€7,50", "Tomatensaus, kaas, ham en ananas"));
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Idefix", "€7,50", "Tomatensaus, kaas, ham en ananas"));
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Idefix", "€7,50", "Tomatensaus, kaas, ham en ananas"));
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Idefix", "€7,50", "Tomatensaus, kaas, ham en ananas"));
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Idefix", "€7,50", "Tomatensaus, kaas, ham en ananas"));
mExampleList.add(new ExampleItem(R.drawable.fotogerecht, "Pizza Idefix", "€7,50", "Tomatensaus, kaas, ham en ananas"));
mRecyclerView =
findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mAdapter = new ExampleAdapter(mExampleList);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
}
public void MyCustomAlertDialog(){
MyDialog = new Dialog(Menu.this);
MyDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
MyDialog.setContentView(R.layout.customdialog);
MyDialog.setTitle("My Custom Dialog");
soepen = MyDialog.findViewById(R.id.soepen);
close = MyDialog.findViewById(R.id.close);
kinder = MyDialog.findViewById(R.id.kinder);
voor = MyDialog.findViewById(R.id.voor);
salades = MyDialog.findViewById(R.id.salades);
diversen = MyDialog.findViewById(R.id.diversen);
pasta = MyDialog.findViewById(R.id.pasta);
alles = MyDialog.findViewById(R.id.alles);
pizza = MyDialog.findViewById(R.id.pizza);
penette = MyDialog.findViewById(R.id.pennette);
ravioli = MyDialog.findViewById(R.id.ravioli);
oven = MyDialog.findViewById(R.id.oven);
rijst = MyDialog.findViewById(R.id.rijst);
vlees = MyDialog.findViewById(R.id.vlees);
vis = MyDialog.findViewById(R.id.vis);
soepen.setEnabled(true);
close.setEnabled(true);
kinder.setEnabled(true);
voor.setEnabled(true);
salades.setEnabled(true);
diversen.setEnabled(true);
pasta.setEnabled(true);
alles.setEnabled(true);
pizza.setEnabled(true);
penette.setEnabled(true);
ravioli.setEnabled(true);
oven.setEnabled(true);
rijst.setEnabled(true);
vlees.setEnabled(true);
vis.setEnabled(true);
soepen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openSoepen();
}
});
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MyDialog.cancel();
}
});
kinder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openKinder();
}
});
voor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openVoor();
}
});
salades.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openKinder();
}
});
diversen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openDiversen();
}
});
pasta.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openPasta();
}
});
salades.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openSalades();
}
});
alles.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openAlles();
}
});
pizza.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openPizza();
}
});
penette.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openPenette();
}
});
ravioli.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openRavioli();
}
});
oven.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openOven();
}
});
rijst.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openRijst();
}
});
vlees.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openVlees();
}
});
vis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openVis();
}
});
MyDialog.show();
}
public void openKinder() {
Intent intent = new Intent(this, Kinder.class);
startActivity(intent);
}
public void openVoor() {
Intent intent = new Intent(this, Voor.class);
startActivity(intent);
}
public void openSoepen() {
Intent intent = new Intent(this, Soepen.class);
startActivity(intent);
}
public void openDiversen() {
Intent intent = new Intent(this, Diversen.class);
startActivity(intent);
}
public void openPasta() {
Intent intent = new Intent(this, Pasta.class);
startActivity(intent);
}
public void openSalades() {
Intent intent = new Intent(this, Pasta.class);
startActivity(intent);
}
public void openAlles() {
Intent intent = new Intent(this, Menu.class);
startActivity(intent);
}
public void openPizza() {
Intent intent = new Intent(this, pizza.class);
startActivity(intent);
}
public void openPenette() {
Intent intent = new Intent(this, penette.class);
startActivity(intent);
}
public void openRavioli() {
Intent intent = new Intent(this, ravioli.class);
startActivity(intent);
}
public void openRijst() {
Intent intent = new Intent(this, rijst.class);
startActivity(intent);
}
public void openVlees() {
Intent intent = new Intent(this, vlees.class);
startActivity(intent);
}
public void openVis() {
Intent intent = new Intent(this, vis.class);
startActivity(intent);
}
public void openOven() {
Intent intent = new Intent(this, oven.class);
startActivity(intent);
}
public void openAfronden() {
Intent intent = new Intent(this, bestelling.class);
startActivity(intent);
}
@Override
public void onItemClick(int position) {
Intent detailIntent = new Intent(this, POPUP.class);
ExampleItem clickedItem = mExampleList.get(position);
detailIntent.putExtra(EXTRA_URL, clickedItem.getText1());
detailIntent.putExtra(EXTRA_CREATOR, clickedItem.getText2());
detailIntent.putExtra(EXTRA_LIKES, clickedItem.getText3());
detailIntent.putExtra(GERECHT, clickedItem.getImageResource());
}
}
ExampleItem.java
package com.opzet.pizzaria.opzet;
public class ExampleItem {
private int mImageResource;
private String mText1;
private String mText2;
private String mText3;
public ExampleItem(int imageResource, String text1, String text2, String
text3) {
mImageResource = imageResource;
mText1 = text1;
mText2 = text2;
mText3 = text3;
}
public int getImageResource() {
return mImageResource;
}
public String getText1() {
return mText1;
}
public String getText2() {
return mText2;
}
public String getText3() {
return mText3;
}
}
ExampleAdapter.java
package com.opzet.pizzaria.opzet;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
public class ExampleAdapter extends
RecyclerView.Adapter<ExampleAdapter.ExampleViewHolder> {
private ArrayList<ExampleItem> mExampleList;
private OnItemClickListner mListner;
public interface OnItemClickListner{
void onItemClick(int position);
}
public void SetOnItemClickListner(OnItemClickListner listner) {
mListner = listner;
}
public class ExampleViewHolder extends RecyclerView.ViewHolder {
public ImageView mImageView;
public TextView mTextView1;
public TextView mTextView2;
public TextView mTextView3;
public ExampleViewHolder(View itemView, final OnItemClickListner listner) {
super(itemView);
mImageView = itemView.findViewById(R.id.imageView);
mTextView1 = itemView.findViewById(R.id.textView);
mTextView2 = itemView.findViewById(R.id.textView2);
mTextView3 = itemView.findViewById(R.id.textView3);
itemView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
if(mListner != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION){
listner.onItemClick(position);
}
}
}
});
}
}
public ExampleAdapter(ArrayList<ExampleItem> exampleList) {
mExampleList = exampleList;
}
@Override
public ExampleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.example_item,
parent, false);
ExampleViewHolder evh = new ExampleViewHolder(v, mListner);
return evh;
}
@Override
public void onBindViewHolder(ExampleViewHolder holder, int position) {
ExampleItem currentItem = mExampleList.get(position);
holder.mImageView.setImageResource(currentItem.getImageResource());
holder.mTextView1.setText(currentItem.getText1());
holder.mTextView2.setText(currentItem.getText2());
holder.mTextView3.setText(currentItem.getText3());
}
@Override
public int getItemCount() {
return mExampleList.size();
}
public void filterList(ArrayList<ExampleItem> filteredList) {
mExampleList = filteredList;
notifyDataSetChanged();
}
}
Menu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.opzet.pizzaria.opzet.MainActivity"
android:focusable="true"
android:focusableInTouchMode="true"
>
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/background"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<ImageView
android:id="@+id/boven"
android:layout_width="180dp"
android:layout_height="wrap_content"
app:srcCompat="@drawable/rechthoekboven"
tools:layout_editor_absoluteX="210dp"
tools:layout_editor_absoluteY="0dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/Menukaart"
android:textColor="#FFFFFF"
android:textSize="21sp"
android:textStyle="italic"
tools:layout_editor_absoluteX="240dp"
tools:layout_editor_absoluteY="32dp"
android:layout_above="@+id/sorteerbalk"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp" />
<ImageView
android:id="@+id/sorteerbalk"
android:layout_width="280dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/sorteerbalk"
tools:layout_editor_absoluteX="160dp"
tools:layout_editor_absoluteY="84dp"
android:layout_below="@+id/boven"
android:layout_centerHorizontal="true" />
<ImageView
android:id="@+id/zoekbalk"
android:layout_width="280dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/zoekbalk"
tools:layout_editor_absoluteX="160dp"
tools:layout_editor_absoluteY="50dp"
android:layout_alignTop="@+id/textView2"
android:layout_alignLeft="@+id/sorteerbalk"
android:layout_alignStart="@+id/sorteerbalk"
android:layout_marginTop="17dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignBottom="@+id/zoekbalk"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:text="@string/sorteren"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="italic"
tools:layout_editor_absoluteX="240dp"
tools:layout_editor_absoluteY="32dp" />
<EditText
android:id="@+id/edittext"
android:layout_width="220dp"
android:layout_height="40dp"
android:layout_above="@+id/textView3"
android:layout_centerHorizontal="true"
android:layout_marginBottom="11dp"
android:textAlignment="center"
android:hint="Zoeken..."/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
android:layout_below="@+id/sorteerbalk"
android:layout_alignParentStart="true" >
</android.support.v7.widget.RecyclerView>
<Button
android:id="@+id/show"
android:layout_width="260dp"
android:layout_height="45dp"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_centerHorizontal="true"
android:text="Button"
android:alpha="0"/>
<ImageView
android:id="@+id/imageView9"
android:layout_width="50dp"
android:layout_height="90dp"
android:layout_above="@+id/sorteerbalk"
android:layout_alignParentEnd="true"
android:layout_marginEnd="32dp"
app:srcCompat="@drawable/bestelling" />
<Button
android:id="@+id/afronden"
android:layout_width="50dp"
android:layout_height="90dp"
android:text="Button"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/imageView9"
android:alpha="0"/>
</RelativeLayout>
ExampleItem.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="4dp"
android:padding="0dp"
android:layout_margin="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:padding="4dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="2dp" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="0dp"
android:text="Line 1"
android:textSize="20sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="100dp"
android:text="Line 2"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="130dp"
android:text="Line 3"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageADD"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentEnd="true"
app:srcCompat="@drawable/add" />
<Button
android:id="@+id/addbutton"
android:layout_width="25dp"
android:layout_height="25dp"
android:text="Button"
android:layout_alignTop="@+id/imageADD"
android:layout_alignParentEnd="true"
android:alpha="0"/>
</RelativeLayout>
</android.support.v7.widget.CardView>