Home > Mobile >  Android listview fuzzy query does not display
Android listview fuzzy query does not display

Time:05-24

The Activity code
Package com. Example. The test;

The import android. App. The Activity;
The import android. The content. The Context;
The import android. Database. Cursor;
The import android. Database. Sqlite. SQLiteDatabase;
The import android. OS. Bundle;
The import android. Text. The Editable;
The import android. Text. TextUtils;
The import android. Text. TextWatcher;
The import android. View. The view;
The import android. Widget. AdapterView;
The import android. Widget. The EditText;
The import android. Widget. ImageView;
The import android. Widget. ListView.
import android.widget.TextView;
The import android. Widget. Toast;


Public class LastOne extends the Activity {

Private EditText mEditText;
Private ImageView mImageView;
Private ListView mListView;
Private TextView mTextView;
The Context Context;
Cursor Cursor;

@ Override
Protected void onCreate (Bundle savedInstanceState) {
Super. OnCreate (savedInstanceState);
The setContentView (R.l ayout. Button6);
The context=this;

InitView ();
}

Private void initView () {
MTextView=(TextView) the findViewById (R.i which extview);
MEditText=(EditText) the findViewById (R.i d.e dittext);
MImageView=(ImageView) the findViewById (R.i d.i mageview);
MListView=(ListView) the findViewById (R.i d.l istview);

//set to delete the picture click event
MImageView. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
//set the EditText content to empty
MEditText. SetText (" ");
//the ListView hidden
MListView. SetVisibility (View. GONE);
}
});

//the EditText add listening
MEditText. AddTextChangedListener (new TextWatcher () {

Public void beforeTextChanged (CharSequence s, int start, int count, int after) {}//text change performed before

@ Override
//perform text change


Public void afterTextChanged (the Editable s) {}//text change after the execution of

@ Override
Public void onTextChanged (CharSequence s, int start,
{int before, int count)
//TODO Auto - generated method stub

}
});

MTextView. SetOnClickListener (new View. An OnClickListener () {

Public void onClick (View v) {
//if the content of the input box is empty, prompt please input search content
If (TextUtils. IsEmpty (mEditText. GetText (), toString (). The trim ())) {
ToastUtils. ShowToast (context, "please enter your want to search the contents of");


} else {
//determine whether the cursor is empty
If (cursor!=null) {
Int columnCount=cursor. GetCount ();
If (columnCount==0) {
ToastUtils. ShowToast (context, "I'm sorry, didn't you want to search the contents of the");
}
}
}

}
});
}

Public void showListView () {
MListView. SetVisibility (the VISIBLE);
//get the content of the input
String STR=mEditText. GetText (). The toString (). The trim ();
//get the database objects
MyOpenHelper MyOpenHelper=new MyOpenHelper (getApplicationContext ());
SQLiteDatabase db=myOpenHelper. GetReadableDatabase ();

//get the cursor
Cursor=db. RawQuery (" select * from people where the name like '% %' "+ STR +" ", null);
MyListViewCursorAdapter adapter=new MyListViewCursorAdapter (context, cursor);

MListView. SetAdapter (adapter);

MListView. SetOnItemClickListener (new AdapterView. OnItemClickListener () {
@ Override
Public void onItemClick (AdapterView<?> The parent, View View, int position, long id) {
//move the cursor to the specified row
Cursor. MoveToPosition (position);
String name=cursor. Get String (cursor. GetColumnIndex (" name "));
ToastUtils. ShowToast (context, name);
}
});
}
}
XML code
Android: layout_width="match_parent"
Android: layout_height="match_parent"
Android: orientation="vertical" & gt;

Android: layout_width="match_parent"
Android: layout_height="43 dp"
Android: background="# 313638"
Android: gravity="center"
The android: orientation="horizontal" & gt;

Android: layout_width="0 dp"
Android: layout_height="match_parent"
Android: layout_weight="1" & gt;

The android: id="@ + id/edittext"
Android: layout_width="match_parent"
Android: layout_height="match_parent"
Android: layout_marginBottom="8 dp"
Android: layout_marginLeft="10 dp"
Android: layout_marginTop="8 dp"
Android: background="# 323232"
Android: hint="please enter the search content"
Android: maxLength="10"
Android: paddingLeft="15 dp"
Android: singleLine="true"
Android: textSize="12 sp/& gt;"

The android: id="@ + id/imageview"
Android: layout_width="20 dp"
Android: layout_height="20 dp"
Android: layout_alignParentRight="true"
Android: layout_centerInParent="true"
Android: paddingRight="20 dp"
The android: SRC="https://bbs.csdn.net/topics/@drawable/cuohao"
Android: visibility="gone"/& gt;


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related