CompaniesActivity extends ExpandableListActivity {
/** Called when the activity is first created. */
EditText edit;
Button search;
String[] text = { "GSK", "sanfoi", "Elilly", "Abbott", "Novartios" };
int textlength = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setListAdapter(new ExampleAdapter(this));
edit=(EditText)findViewById(R.id.edtxt);
// Search functionality
final ArrayList<String> text_sort = new ArrayList<String>();
search = (Button) findViewById(R.id.btn);
edit = (EditText) findViewById(R.id.edtxt);
ExpandableListView listview = (ExpandableListView) findViewById(R.id.list);
listview.setAdapter(new MyCustomAdapter(text));
search.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
textlength = edit.getText().length();
text_sort.clear();
for (int i = 0; i < text.length; i++) {
if (textlength <= text[i].length()) {
if (edit.getText().toString().equalsIgnoreCase(
(String) text[i].subSequence(0, textlength))) {
text_sort.add(text[i]);
}
}
}
setListAdapter((ExpandableListAdapter) new MyCustomAdapter(text_sort, null));
}
});
}
class MyCustomAdapter extends BaseAdapter {
String[] data_text;
MyCustomAdapter() {
}
MyCustomAdapter(String[] text) {
data_text = text;
}
MyCustomAdapter(ArrayList<String> text, ArrayList<Integer> image) {
data_text = new String[text.size()];
for (int i = 0; i < text.size(); i++) {
data_text[i] = text.get(i);
}
}
public int getCount() {
return data_text.length;
}
public String getItem(int position) {
return null;
}
public long getItemId(int position) {
return position;
}
}
this my layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/edtxt"
android:layout_width="250dp"
android:layout_height="45dp"
android:inputType="none" />
<Button
android:id="@+id/btn"
android:layout_width="65dp"
android:layout_height="50dp"
android:layout_marginBottom="1dp"
android:layout_marginRight="1dp"
android:layout_marginTop="1dp"
android:text="Search"
android:textSize="13sp" />
</LinearLayout>
<ExpandableListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="20px"
android:textSize="40px"
/>
</LinearLayout>
can you please help any one this .,
i used edittext and search button in layout file and i search is not happening how to reslove this issues
-- You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment