gpt4 book ai didi

android - 知道android :onClick came from and retrvieve children data在哪里

转载 作者:行者123 更新时间:2023-11-29 20:23:29 25 4
gpt4 key购买 nike

我的标题可能有点不对,但我无法用这么短的词更好地解释自己。

我有 ExpandableListView,每个都有两个 child 。它们是在同一 Activity 中创建的,因为我想用来自 child 的数据来执行 Intent。问题是我不知道如何检索 child 数据。

这是给 children 数据的方法。

private void displayContacts() {
ArrayList<String> namesmails = getNameEmailDetails();
ArrayList<String> namesphones = getPeopleWithNumbers();
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
int counter = 0;
for (int i = 0; i<namesmails.size();i = i+2) {
//namesmails[0] == name && namesmails[1] == phone && namesmails[2] == email
String name = namesmails.get(i);
String mail = namesmails.get(i + 1);
String phone = returnNumber(namesphones,name);
listDataHeader.add(name);
List<String> currentName = new ArrayList<String>();
currentName.add(phone);
currentName.add(mail);
listDataChild.put(listDataHeader.get(counter), currentName);
counter += 1;
}
}

我想创建邮件 Intent ,因此 listDataChild 中的 currentName.get(1) 是邮件的收件人(例如:example@example.org).

为此我创建了一个方法:

public void sendMail() {
//This function is called out on the list_item click!
Intent mailIntent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND
mailIntent.setType("text/plain");
mailIntent.setData(Uri.parse("mailto:" + HERENEEDSTOBEADDRESS));
mailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(mailIntent,1);
setResult(RESULT_CANCELED, mailIntent);

}

并给 list_item.xml onClick 值:

<TextView
android:id="@+id/lblListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:onClick="sendMail()"/>

我怎样才能将数据发送到 sendMail()

一些额外的信息。我正在尝试在 ExpandedListView 中显示联系人,其中名称是标题,电子邮件和电话是特定元素的子元素,因此每个列表项都是根据用户联系人大小动态创建的.如果单击电子邮件 list_item.get(1),则会启动 sendMail() 并触发 Intent 以发送邮件。

最佳答案

试试这个

<TextView
android:id="@+id/lblListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:onClick="sendMail"/>

在你的java代码中

public void sendMail(View v) {
//This function is called out on the list_item click!
String email = ((TextView)v).getText().toString();
Intent mailIntent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND
mailIntent.setType("text/plain");
mailIntent.setData(Uri.parse("mailto:" + email));
mailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(mailIntent,1);
setResult(RESULT_CANCELED, mailIntent);
}

关于android - 知道android :onClick came from and retrvieve children data在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32848848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com