【问题标题】:Linkify in Android FragmentAndroid Fragment 中的 Linkify
【发布时间】:2013-03-24 06:43:53
【问题描述】:

我正在尝试在 Fragment 中使用 linkify,但我无法将其实际链接化,也找不到有关如何正确使用它的文档。如果有人可以提供帮助,那就太好了!

ContactFragment.java:

public class ContactFragment extends SherlockFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup group,
            Bundle saved) {

        View V = inflater.inflate(R.layout.activity_contact_fragment, group, false);

        TextView myEmail= (TextView) V.findViewById(R.id.textView1);
        myEmail.setText("info@komodostudios.com");
        Linkify.addLinks(myEmail, Linkify.EMAIL_ADDRESSES);

        return inflater.inflate(R.layout.activity_contact_fragment, group, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }
}

activity_contact_fragment.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ContactFragment" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="info@komodostudios.com" />

</RelativeLayout>

【问题讨论】:

  • myEmail.setMovementMethod(LinkMovementMethod.getInstance());添加这个
  • 这不会改变任何事情
  • 文字显示了吗??

标签: android android-fragments linkify


【解决方案1】:

您从 onCreateView 方法返回了错误的 View。应该是return V; 而不是return inflater.inflate(R.layout.activity_contact_fragment, group, false);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 2013-03-05
    • 2013-04-10
    相关资源
    最近更新 更多