So now I'm going to look at the code
that I added to implement the scrolling
list of all the dinners.
So the first thing I'm going to do is in
the com.example.android.dinner package,
I'm going to add a new Java class
called ShowAllDinnersActivity.
This class extends ListActivity.
It knows how to get a list
of all the dinners.
It uses an adapter to display
all the dinners in the list, and
it defines the onListItemClick, so
that when an item on the list is
clicked we send an intent to start
the OrderDinnerActivity, and
passing in the selectedDinner.
Now over, in Main Activity, we add the
showDinnerList method, which is going to
be invoked whenever somebody clicks on
the show me all the dinners button.
And all this method does,
is it sends an intent to start
the ShowAllDinnersActivity.
So that's it for the code, but
now we need to do the layouts.
The first thing I'm going to do is
add the button to the main screen,
to list all the dinners.
And there it is, show all the dinners.
But I'm not done with the layout yet.
I need to add
the listalldinners.xml file,
which is a list of all the dinners.
So we need to add
the showdinnerinrow.xml layout file,
which is a layout for
each dinner entry in the list.
All right, that should do it.
So, I'm going to redeploy my app and
hopefully we'll see
the changes in the UI.
So of course, one more thing you
need to do in the code is to update
the AndroidManifest.xml to include your
new class, ShowAllDinnersActivity.
If you don't do this, it It won't work.
So that's all there is to it.
Now I'm going to run my app again,
and let's see if it works.
So, I press my Show All the Dinners,
and let's see.
Oh, and there's my list of dinners.
Cool.
والآن سألقي نظرة على التعليمة البرمجية
التي أضفتها لتطبيق قائمة التمرير
الخاصة بجميع وجبات العشاء.
لذلك أول شيء سأقوم به سيكون في
الحزمة com.example.android.dinner،
سأضيف فئة Java جديدة
تسمى ShowAllDinnersActivity.
ستقوم هذه الفئة بتمديد ListActivity.
والتي تعرف كيفية الحصول على قائمة
بجميع وجبات العشاء.
تستخدم القائمة مهايئ لعرض جميع وجبات
العشاء في القائمة
كما تحدد onListItemClick، بحيث عندما يتم
النقر على عنصر في القائمة
نرسل تعليمة هدف لبدء
OrderDinnerActivity،
والمرور عبر selectedDinner.
والآن، في Main Activity، نضيف
الأسلوب showDinnerList، والذي
سيتم استدعاؤه كلما ينقر شخص على
الزر show me all the dinners.
وكل ما يفعله هذا الأسلوب،
هو إرسال التعليمة الهدف لبدء
ShowAllDinnersActivity.
هذا ما يخص التعليمة البرمجية، لكن
الآن نريد تنفيذ التخطيطات.
أول شيء سأقوم به هو
إضافة الزر إلى الشاشة الرئيسية،
لسرد كل وجبات العشاء.
ويوجد هناك الزر show all the dinners.
لكني لم أنته من التخطيط بعد.
أريد إضافة
الملف listalldinners.xml،
وهو قائمة بجميع وجبات العشاء.
لذلك نحتاج إلى إضافة
الملف showdinnerinrow.xml،
الذي عبارة عن تخطيط
لكل إدخال وجبة عشاء في القائمة.
حسنًا، ينبغي أن ينجز ذلك المهمة.
حسنًا، سأقوم بإعادة نشر التطبيق
وآمل أن نرى
التغييرات في واجهة المستخدم.
وبالطبع، هناك شيء آخر تحتاج إلى
القيام به في التعليمة البرمجية وهو تحديث
AndroidManifest.xml ليتضمن الفئة
الجديدة ShowAllDinnersActivity.
إذا لم تقم بذلك، فلن يعمل.
حسنًا هذا هو كل ما في الأمر.
والآن سأقوم بتشغيل التطبيق مرة أخرى،
ودعنا نرى ما إذا كان يعمل.
حسنًا، سأضغط على Show All the Dinners،
ودعنا نرى.
رائع، هذه هي قائمة وجبات العشاء.
رائع.
Agora vou analisar o
código que eu adicionei
para implementar a lista de rolagem
de todos os jantares.
A primeira coisa que vou fazer será
acessar o
pacote com.example.android.dinner
e adicionar uma nova classe Java
chamada ShowAllDinnersActivity.
Essa classe ampliará a ListActivity.
Ela sabe como obter uma lista
de todos os jantares.
Ela usa um adaptador para exibir
todos os jantares da lista
e define o onListItemClick
de modo que quando um item da lista é
clicado, uma intenção seja enviada
para iniciar a OrderDinnerActivity
e passar o selectedDinner.
Em MainActivity,
adicionamos o método showDinnerList,
que será chamado
sempre que alguém clicar no
botão "mostrar todos os jantares".
E esse método
envia uma intenção
para iniciar ShowAllDinnersActivity.
Esse é o código,
mas agora precisamos fazer os layouts.
A primeira coisa que vou fazer
é adicionar o botão à tela principal
para listar todos os jantares.
Aí está...
mostrar todos os jantares.
Mas ainda não terminei o layout.
Tenho que adicionar
o arquivo listalldinners.xml,
que é uma lista de todos os jantares.
E temos que adicionar
o arquivo de layout showdinnerinrow.xml,
que é um layout
para cada entrada de jantar da lista.
Certo, acho que não falta mais nada.
Vou reimplantar o meu aplicativo
e espero ver
as mudanças na UI.
E, é claro,
uma outra coisa que preciso fazer
no código é atualizar
o AndroidManifest.xml
para incluir a sua nova classe
ShowAllDinnersActivity.
Se você não fizer isso,
ele não funcionará.
Então, isso é tudo.
Agora vou executar o aplicativo de novo
e ver se funcionou.
Vou pressionar o botão Mostrar todos os jantares
e vamos ver...
Ah! Aí está a minha lista de jantares.
Legal.
现在我要查看一下为实现所有晚餐滚动列表而
添加的代码
我要做的第一件事在 com.example.android.dinner 包内
添加一个名为 ShowAllDinnersActivity 的新 Java 类
该类对 ListActivity 进行扩展
它知道如何获得所有晚餐列表
它使用适配器来显示列表中的所有晚餐
并能定义 onListItemClick 因此 当点击列表上的项目时
我们发送 intent 以启动 OrderDinnerActivity 并
传递 selectedDinner
现在结束了 在 MainActivity 中 我们添加 showDinnerList 方法
当有人点击“为我显示所有晚餐”按钮时就会调用该方法
使用该方法
就是发送 intent 以启动 ShowAllDinnersActivity
对于代码就是这样 但是现在我们需要完成布局
我要做的第一件事是将按钮添加到主页面
以显示所有晚餐
这就是 Show All the Dinners
但是我还仍然没有完成布局
我需要添加 listalldinners.xml 文件
该文件是所有晚餐的列表
因此我需要添加 showdinnerinrow.xml 布局文件
该文件是每个晚餐条目在列表中的布局
好了 应该这样做
所以 我要重新部署我的应用
希望我们会看到用户界面的变化
当然 在代码中你需要做的另一件事情是更新
AndroidManifest.xml 以包含新类 ShowAllDinnersActivity
如果不这样做 它就不会起作用
这就是全部要讲的内容
现在我要再次运行我的应用 我们看看它是否可正常工作
我按下 Show All the Dinners 按钮 我们来看看结果如何
我的晚餐列表显示出来了
太好了!