我的列表视图中有一个编辑文本和一个保存按钮。当用户单击保存按钮时,我必须清除文本。我试过像
txtDescription.setText("");
但没有奏效。任何人都知道为什么它不起作用?适配器类已附加
请帮助我,在此先感谢!
private class ListAdapters extends ArrayAdapter<ApplicationBean> {
private ArrayList<ApplicationBean> items;
private int position;
public ListAdapters(Context context, int textViewResourceId,
ArrayList<ApplicationBean> mTitleList) {
super(context, textViewResourceId, mTitleList);
this.items = mTitleList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
this.position = position;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.applicationlistitem, null);
}
final ApplicationBean o = (ApplicationBean) items.get(position);
if (o != null) {
txtDescription = (EditText) v
.findViewById(R.id.description_text);
submitButton = (Button) v.findViewById(R.id.submit_btn);
submitButton.setTag(position);
submitButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PostRequest p = new PostRequest(Integer.parseInt(v
.getTag().toString()));
p.execute();
}
});
}
return v;
}
@Override
public int getItemViewType(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return items.size();
}
}
private class PostRequest extends AsyncTask<Void, Void, String> {
ProgressDialog dlgprogress;
int position;
public PostRequest(int selectedIndex) {
position = selectedIndex;
}
@Override
protected void onPostExecute(String result) {
dlgprogress.dismiss();
final Dialog dlg = new AlertDialog.Builder(mContext)
.setTitle("Message")
.setMessage(result)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int whichButton) {
dlgprogress.dismiss();
dlgprogress.cancel();
txtDescription.setText("");
}
}).create();
dlg.show();
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
dlgprogress = ProgressDialog.show(mContext, "", "Please wait");
// dlgprogress.show(mContext, "", "Please wait");
super.onPreExecute();
}
@Override
protected String doInBackground(Void... arg0) {
//do something.............
//..........................
dlgprogress.dismiss();
return rsponse;
}
}
应用程序列表项.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF">
<LinearLayout
android:id="@+id/lineatlayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DESCRIPTION : "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<EditText
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="textMultiLine"
android:textColor="#000000">
</EditText>
</LinearLayout>
<Button
android:id="@+id/submit_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT" />
</LinearLayout>