知道android:onClick来自哪里并追踪儿童数据

时间:2015-09-29 16:08:31

标签: android email

我的头衔可能有点不对,但我无法用这么简短的话来解释自己。

我有ExpandableListView,每人有两个孩子。他们在与我想对孩子们的数据进行Intent相同的活动中创建。问题是我不知道如何检索儿童数据。

这是为孩子们提供数据的方法。

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;
    }
}

我想创建邮件意图,因此来自currentName.get(1)的{​​{1}}是邮件的收件人(例如:listDataChild)。

为此,我创建了一个方法:

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)并触发Intent以发送邮件。

2 个答案:

答案 0 :(得分:1)

您还可以在XML上添加<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" android:tag="mail@address.com"/> <!-- Attention to this line! --> 以获取点击的来源。类似的东西:

sendMail()

然后,在// Don't forget to put the View as a parameter for the onClick to work. // This function is called out on the list_item click! public void sendMail(View v) { String addr = v.getTag(); // Get the tag. Intent mailIntent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND mailIntent.setType("text/plain"); mailIntent.setData(Uri.parse("mailto:" + addr)); mailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityForResult(mailIntent,1); setResult(RESULT_CANCELED, mailIntent); } 方法上,检索标记:

ora-12609 tns receive timeout occurred

答案 1 :(得分:1)

试试这个

<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);
}