我正在开发一个应用程序,其中我有一个listview。在每行中有一个textview和一个AutoCompleteTextview。现在我想要的是使autocompletetextview可编辑,即当我的列表中填充了一些数据时,我想编辑一些autocompletetexviews然后将更新的数据发送到服务器。有什么解决方案吗?我浪费了我2天的时间,我迫切需要这个。
这是我的customAdapter's getview()
方法。我可以在listview中成功填充数据,并添加了" addOnTextChangedListener
"到autocomletetextview。但是,当我过滤数据时,它无法设置为auotocompletetext,即autocomtextview.settext(filtereddata)
没有执行。我在onTextChanged()
中获取过滤文本在我的代码中我写了这个,但我不知道实际放在哪里。
public View getView(final int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater= (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(convertView==null)
{
convertView=inflater.inflate(R.layout.new_applwizard_extuser_listrow,null);
TextView appl_Name=(TextView)convertView.findViewById(R.id.ext_app_name);
auto_brand_Name=(AutoCompleteTextView)convertView.findViewById(R.id.ext_auto_brand_txt);
auto_brand_Name.setFocusable(true);
auto_brand_Name.setFocusableInTouchMode(true);
ToggleButton toggle_status=(ToggleButton)convertView.findViewById(R.id.ext_toggle_cover);
LinearLayout ll_save_btn=(LinearLayout)convertView.findViewById(R.id.ll_ext_btn_appsubmit);
try
{
appl_Name.setText(alApplianceDetails.get(position).getAppliance_Name().toString());
if(alApplianceDetails.get(position).getStatus()==true)
{
toggle_status.setChecked(true);
}
else
{
toggle_status.setChecked(false);
}
if(alApplianceDetails.get(position).getBrand_Id()!=0)
{
String brand_name=null;
brand_name=dbHandler.getBrand_id(String.valueOf(alApplianceDetails.get(position).getBrand_Id()));
Log.d("brand name", brand_name);
auto_brand_Name.setText(brand_name);
}
else
{
Log.d("brand name", "no brand");
}
try
{
auto_brand_Name.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent,View view, int position, long id)
{
String selection = parent.getItemAtPosition(position).toString();
//auto_brand_Name.setText(selection);
Log.d("adpter value..",""+parent.getAdapter().getItem(position).toString());
try
{
AutoCompleteTextView brnd=(AutoCompleteTextView)view;
//Log.d( "text value.....",brnd.getText().toString());
brnd.setText(filteredVal);
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}
catch(Exception e)
{
}
auto_brand_Name.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
if(alApplianceDetails.get(position).getAppliance_TypeId()!=0)
{
String app_name=null;
app_name=dbHandler.getApp_id(String.valueOf(alApplianceDetails.get(position).getAppliance_TypeId()));
appliance=app_name;
Log.d("app_name",app_name);
}
else
{
Log.d("app_name", "No App");
}
alBrands.clear();
getBrand();
for(int i=0;i<alBrand_Common_Objects.size();i++)
{
alBrands.add(alBrand_Common_Objects.get(i).getcommon_name());
}
Log.d("brands_list", alBrands.toString());
aaBrand =new ArrayAdapter<String>(activity.getApplicationContext(), R.layout.spinner_item, alBrands);
auto_brand_Name.setThreshold(1);
auto_brand_Name.setAdapter(aaBrand);
auto_brand_Name.postInvalidate();
auto_brand_Name.invalidate();
auto_brand_Name.showDropDown();
aaBrand.setNotifyOnChange(true);
//aaBrand.notifyDataSetChanged();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
Log.d("filtered value...", s.toString());
filteredVal=s.toString();
//auto_brand_Name.setText(s.toString());
}
@Override
public void afterTextChanged(Editable s)
{
try
{
//auto_brand_Name.setText(filteredVal);
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
}
return convertView;
}