将元素添加到listview_arr中,其余代码如下...:-
listview_arr = new String[listview_array_location.length];
listview_arr = listview_array;
setListAdapter(new bsAdapter(this));
et.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
}
public void beforeTextChanged(CharSequence s,
int start, int count, int after)
{
}
public void onTextChanged(CharSequence s,int start, int before, int count)
{
Log.d("count","count==>"+s);
textlength = et.getText().length();
array_sort.clear();
for (int i = 0; i < listview_array_location.length; i++)
{
if (textlength <= listview_array_location[i].length())
{
if(et.getText().toString().equalsIgnoreCase((String)listview_array_location[i].subSequence(0,textlength)))
{
array_sort.add(listview_array[i]);
}
}
}
AppendList(array_sort);
}
});
}
public void AppendList(ArrayList<String> str)
{
listview_arr = new String[str.size()];
listview_arr = str.toArray(listview_arr);
setListAdapter(new bsAdapter(this));
}
public class bsAdapter extends BaseAdapter
{
Activity cntx;
public bsAdapter(Activity context)
{
this.cntx=context;
}
public int getCount()
{
return listview_arr.length;
}
public Object getItem(int position)
{
return listview_arr[position];
}
public long getItemId(int position)
{
return listview_array.length;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
View row=null;
LayoutInflater inflater=cntx.getLayoutInflater();
row=inflater.inflate(R.layout.search_list_item, null);
TextView tv=(TextView)row.findViewById(R.id.title);
Button Btn01=(Button)row.findViewById(R.id.Btn01);
Button Btn02=(Button)row.findViewById(R.id.Btn02);
tv.setText(listview_arr[position]);
Btn01.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(SearchUser.this, "Button 1 "+listview_arr[position], Toast.LENGTH_SHORT).show();
int color = PreferenceManager.getDefaultSharedPreferences(
SearchUser.this).getInt(COLOR_PREFERENCE_KEY, Color.WHITE);
new ColorPickerDialog(SearchUser.this, SearchUser.this, color).show();
}
});
Btn02.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(SearchUser.this, "Button 2 "+listview_arr[position], Toast.LENGTH_SHORT).show();
}
});
return row;
}
}