在我的应用程序中,我有三个选项卡。在每个选项卡中,我都有一些控件。当我尝试为我的按钮实现 onClick 方法时,我发现按钮没有响应手势,更具体地说,是点击。
这是选项卡的类:
package com.telkitty.myPetProject
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.provider.Contacts;
import android.provider.ContactsContract;
public class ContactPage extends Fragment {
private static final int CONTACT_PICKER_RESULT = 1001;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Activity activity = getActivity();
if (activity != null)
{
addListenerOnButton();
}
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.contact_page, container, false);
return view;
}
public void onListItemClick(ListView l, View v, int position, long id) {
Activity activity = getActivity();
}
public void addListenerOnButton()
{
Button add = (Button) getView().findViewById(R.id.add_button);
add.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.CONTENT_URI);
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}});
}
}
这是xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/edit_button"
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"
android:text="@string/edit_contact"/>
<Button
android:id="@+id/add_button"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:text="@string/add_contact"/>
<ListView
android:id="@+id/contact_list"
android:layout_width="320dp"
android:layout_height="380dp"
android:paddingTop="50dp" >
</ListView>
</RelativeLayout>
我做错了什么?