<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/edt_num"
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="@string/phone_number"
android:paddingLeft="15dp"
android:textColor="@color/black"
android:textSize="18sp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/line_gray" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:listSelector="@drawable/list_item_selector" />
</LinearLayout>
public abstract class AbsSearchFragment extends Fragment implements View.OnClickListener, AbsListView.OnScrollListener, SearchManager.OnDismissListener, AdapterView.OnItemClickListener {
public interface OnSearchItemListener {
void onContactSelected(Contact contact);
}
private static final String TAG = AbsSearchFragment.class.getSimpleName();
protected View view;
protected ListView listView;
protected EditText editText;
private SearchManager searchManager;
private ContactListCursorAdapter mAdapter;
private Cursor mCursor;
private int mPosition = ListView.INVALID_POSITION;
private boolean mSearchResultTryAgain;
private boolean mLoaded = false;
private OnSearchItemListener mCallback;
private AbsListView.OnScrollListener scrollListener = new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (!mLoaded && scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
mAdapter.loadNextPage();
mLoaded = true;
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
};
private boolean checkPhoneNumber(String number) {
if (TextUtils.isEmpty(number)) {
toast(R.string.str_empty_number);
return false;
}
if (!TextUtils.isDigitsOnly(number) && !PhoneNumberUtils.isGlobalPhoneNumber(number)) {
toast(R.string.str_invalid_number);
return false;
}
return true;
}
public void startDial(String number, int flags) {
if (!checkPhoneNumber(number)) {
return;
}
Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
dialIntent.addFlags(flags);
startActivitySafely(dialIntent);
}
edt_num.requestFocus();
edt_num.setSelection(edt_num.getText().toString().trim().length());
private void initUI() {
//获取界面控件的引用
listView = (ListView) view.findViewById(android.R.id.list);
editText = (EditText) view.findViewById(R.id.edt_num);
//设置适配器
mAdapter = new ContactListCursorAdapter(getActivity(), mCursor);
mAdapter.setOnLoadListener(this);
listView.setAdapter(mAdapter);
//设置搜索管理器
searchManager = new SearchManager(getActivity(), mHandler);
searchManager.setAdapter(mAdapter);
searchManager.setOnDismissListener(this);
//为ListView设置点击事件监听器
listView.setOnItemClickListener(this);
//为ListView设置滚动事件监听器
listView.setOnScrollListener(scrollListener);
}
标签: 华为手机拨