こんにちは、誰でもこれで私を助けてくれますか? リストビューを作成するためにカスタム アダプターを使用しています。リストビューには、editText を保持するハッシュマップがあります。私の問題は、editText に何かを入力してリストビューをスクロールすると、editText の内容が失われることです。どうすればいいですか?私は現在スタックしています。以下は私のコードを示しています:
*************
myCustomAdapterIreport = new CustomArrayAdapterIreport(getApplicationContext(), mylist, R.layout.attribute_selected_ireport_file,
new String[]{FILE_NAME, DESC, UPLOADED_BY, DATE_UPLOADED, ACTION, ID, FILE_URI},
new int[]{R.id.tv_iFile, R.id.txt_iDesc,R.id.tv_iUploadedBy,R.id.tv_iDateUploaded, R.id.tv_iAction,
R.id.tv_RowId, R.id.tv_iUri}, true);
lv_AttachedFileData.setAdapter(myCustomAdapterIreport);
***********************
public class CustomArrayAdapterIreport extends SimpleAdapter
{
private Context context;
private final ArrayList<HashMap<String, String>> mData;
private ArrayList<HashMap<String, String>> unfilteredValues;
private boolean chosenValues, ismarkAll = true;
private int resource;
private String[] from;
private int[] to;
private SimpleFilter mFilter;
private ArrayList<String> arraylistAttach, arraylistAttachId;
S_10th_IReportMain iReport;
public CustomArrayAdapterIreport(Context context, ArrayList<HashMap<String, String>> data, int resource, String[] from,
int[] to, boolean chosenValues)
{
super(context, data, resource, from, to);
this.context = context;
mData = data;
this.unfilteredValues = mData;
this.resource = resource;
this.from = from;
this.to = to;
this.arraylistAttach = new ArrayList<String>();
this.arraylistAttachId = new ArrayList<String>();
this.chosenValues = chosenValues;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = LayoutInflater.from(context);
View rowView = null;
if(rowView == null)
{
try{
rowView = inflater.inflate(resource, null, true);
textViewTitle = (TextView) rowView.findViewById(to[0]);
txt_Desc = (EditText) rowView.findViewById(to[1]);
tv_CreatedBy = (TextView) rowView.findViewById(to[2]);
tv_DateCreated= (TextView) rowView.findViewById(to[3]);
final TextView tv_Action = (TextView) rowView.findViewById(to[4]);
final TextView tv_rowId = (TextView) rowView.findViewById(to[5]);
tv_Uri = (TextView)rowView.findViewById(to[6]);
Typeface tf= Typeface.createFromAsset(context.getAssets(), "Gothic_Regular.TTF");
textViewTitle.setTypeface(tf);
txt_Desc.setTypeface(tf);
tv_CreatedBy.setTypeface(tf);
tv_DateCreated.setTypeface(tf);
tv_Action.setTypeface(tf);
final String FileKey = from[0];
String DescKey = from[1];
String UploadedByKey = from[2];
String DateUploadKey = from[3];
String ActionKey = from[4];
final String idKey = from[5];
String FileUri = from[6];
final String FileName = unfilteredValues.get(position).get(FileKey).toString();
String Desc = unfilteredValues.get(position).get(DescKey).toString();
String UploadedBy = unfilteredValues.get(position).get(UploadedByKey).toString();
String DateUpload = unfilteredValues.get(position).get(DateUploadKey).toString();
String Action = unfilteredValues.get(position).get(ActionKey).toString();
String AttachId = unfilteredValues.get(position).get(idKey).toString();
String FileNameUri = unfilteredValues.get(position).get(FileUri).toString();
textViewTitle.setText(FileName);
txt_Desc.setText(Desc);
tv_CreatedBy.setText(UploadedBy);
tv_DateCreated.setText(DateUpload);
tv_Action.setText(Action);
tv_rowId.setText(AttachId);
tv_Uri.setText(FileNameUri);
textViewTitle.setId(position);
txt_Desc.setId(position);
tv_CreatedBy.setId(position);
tv_DateCreated.setId(position);
tv_Uri.setId(position);
final String id = tv_rowId.getText().toString();
tv_Action.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
AlertDialog.Builder builder = new AlertDialog.Builder(S_10th_IReportMain.this);
builder
.setTitle("Warning!")
.setMessage("Are you sure you want delete this file?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int id)
{
deleteMyFilesiReport(position);
Toast.makeText(getApplicationContext(), "Deleted", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int id)
{
dialog.cancel();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
}catch (Exception e){
e.printStackTrace();
}
catch (OutOfMemoryError E){
E.printStackTrace();
}
}
return rowView;
}
public ArrayList<String> getArrayListConsumer() {
return this.arraylistAttach;
}
public ArrayList<String> getArrayListConsumerId() {
return this.arraylistAttachId;
}
public Filter getFilter() {
if (mFilter == null) {
mFilter = new SimpleFilter();
}
return mFilter;
}
public int getCount() {
return unfilteredValues.size();
}
private class SimpleFilter extends Filter {
@SuppressWarnings("unchecked")
@Override
protected FilterResults performFiltering(CharSequence prefix) {
FilterResults results = new FilterResults();
String prefixString = null == prefix ? null : prefix.toString().toLowerCase();
ArrayList<HashMap<String, String>> unfilteredValues;
if (null != prefixString && prefixString.length() > 0) {
synchronized (mData) {
unfilteredValues = (ArrayList<HashMap<String, String>>) mData.clone();
}
for (int i = unfilteredValues.size() - 1; i >= 0; --i) {
HashMap<String, String> h = unfilteredValues.get(i);
String str = (String)h.get(from[0]).toString();
if (!str.toLowerCase().startsWith(prefixString)) {
unfilteredValues.remove(i);
}
}
//Log.i(Constants.TAG, String.valueOf(unfilteredValues.size()));
results.values = unfilteredValues;
results.count = unfilteredValues.size();
} else {
synchronized (mData) {
results.values = mData;
results.count = mData.size();
}
}
return results;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
//noinspection unchecked
unfilteredValues = (ArrayList<HashMap<String, String>>) results.values;
notifyDataSetChanged();
}
}
}