gpt4 book ai didi

android - 清除 ListView 中的 Android 编辑文本

转载 作者:搜寻专家 更新时间:2023-11-01 09:04:13 25 4
gpt4 key购买 nike

我的 ListView 中有一个编辑文本和一个保存按钮。当用户单击保存按钮时,我必须清除文本。我试过像

txtDescription.setText("");

但是没用。任何人都知道为什么它不起作用? Adapter类附后

请帮助我,在此先感谢!!

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>

最佳答案

维护 ListView 的自定义适配器类

 public View getView(final int position, View convertView, ViewGroup parent)
{
View row=null;
Context context = getApplicationContext();
LayoutInflater inflater=cntx.getLayoutInflater();
row=inflater.inflate(R.layout.search_list_item, null);

EditText txtDescription= (EditText)row.findViewById(R.id.txtDescription);
Button Savebtn = (Button)row.findViewById(R.id.SaveBtn);

Savebtn.setOnClickListener(new OnClickListener(){

public void onClick(View v)
{
txtDescription.setText("");
// And your additional coding
}
});
}

如果您不熟悉 ListView 的自定义适配器,请检查 here

关于android - 清除 ListView 中的 Android 编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13151765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com