I am working on a CRM app in android, in which, I am showing details of all contacts in a list view. Now, my requirement is when I click on a particular item in the list, it should only display the details about selected contact, such as, name, address, email, etc.. The data is coming from XML file, which I am parsing using SAX Parser. How can I query a XML to get selected data?
我正在开发一个Android应用程序中的CRM应用程序,其中,我在列表视图中显示所有联系人的详细信息。现在,我的要求是当我点击列表中的特定项目时,它应该只显示有关所选联系人的详细信息,例如姓名,地址,电子邮件等。数据来自XML文件,我正在解析使用SAX Parser。如何查询XML以获取所选数据?
1 个解决方案
#1
1
You are filling the ListView
using Adapter
right? Now you can get the item at the selected view inside the ListView
and pass this item to an Activity
.
您正在使用适配器填充ListView吗?现在,您可以在ListView内的选定视图中获取该项目,并将此项目传递给活动。
E.g. inside your Adatper
class implement the onItemClickListener
:
例如。在你的Adatper类中实现onItemClickListener:
public void onItemClick(AdapterView<?> a, View v, int position, long l) {
// Remembers the selected Index
Data item =getItem(position);
Intent intent = new Intent(getApplicationContext(), DetailedActivity.class);
intent.put("object",item);
startActivity(intent);
}
Note: the item "Data" class should implement the Parsable
interface so it can be passed to the Activity
in your DetailedActivity
onCreate
method get that object and update the UI
based on its Values.
注意:项“Data”类应该实现Parsable接口,因此可以将它传递给DetailedActivity onCreate方法中的Activity获取该对象并根据其值更新UI。
#1
1
You are filling the ListView
using Adapter
right? Now you can get the item at the selected view inside the ListView
and pass this item to an Activity
.
您正在使用适配器填充ListView吗?现在,您可以在ListView内的选定视图中获取该项目,并将此项目传递给活动。
E.g. inside your Adatper
class implement the onItemClickListener
:
例如。在你的Adatper类中实现onItemClickListener:
public void onItemClick(AdapterView<?> a, View v, int position, long l) {
// Remembers the selected Index
Data item =getItem(position);
Intent intent = new Intent(getApplicationContext(), DetailedActivity.class);
intent.put("object",item);
startActivity(intent);
}
Note: the item "Data" class should implement the Parsable
interface so it can be passed to the Activity
in your DetailedActivity
onCreate
method get that object and update the UI
based on its Values.
注意:项“Data”类应该实现Parsable接口,因此可以将它传递给DetailedActivity onCreate方法中的Activity获取该对象并根据其值更新UI。