我ListView
使用放入 hasmap 的数据库中的数据填充了我的数据。中的每一行(哈希图)ListView
都有EditText
。我的问题是我不知道如何获取EditText
hasmap 中的值。
这是代码:
selectedFileNames = new String[listSelectedFileNames.size()];
for (int i = 0; i < listSelectedFileNames.size(); i++) {
selectedFileNames[i] = listSelectedFileNames.get(i);
}
selectedFileUri = new String[listSelectedFileUri.size()];
for (int i = 0; i < listSelectedFileUri.size(); i++) {
selectedFileUri[i] = listSelectedFileUri.get(i);
}
String myDate = tv_Date.getText().toString();
mylist = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < listSelectedFileNames.size(); i++)
{
HashMap<String, String> map = new HashMap<String, String>();
map.put(FILE_NAME, selectedFileNames[i]);
map.put(DESC,"");
map.put(UPLOADED_BY, "User");
map.put(DATE_UPLOADED, myDate);
map.put(ACTION, "Delete");
map.put(ID, String.valueOf(i));
map.put(FILE_URI, selectedFileUri[i]);
mylist.add(map);
}
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);
这是我的适配器的 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="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/listHeader1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="@+id/tv_iFile"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="13sp"
android:textColor="@color/black"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:paddingRight="3dp"/>
<EditText
android:id="@+id/txt_iDesc"
android:layout_width="0dp"
android:layout_height="22dp"
android:layout_weight="1"
android:textSize="13sp"
android:textColor="@color/black"
android:singleLine="true"
android:paddingRight="3dp"
android:gravity="center"
android:background="@drawable/bg_ireporttxtbg"
android:ems="10"/>
<TextView
android:id="@+id/tv_iUploadedBy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="13sp"
android:textColor="@color/black"
android:gravity="center"
android:singleLine="true"/>
<TextView
android:id="@+id/tv_iDateUploaded"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="13sp"
android:gravity="center"
android:clickable="true"
android:textColor="@color/black"/>
<TextView
android:id="@+id/tv_iAction"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="13sp"
android:textColor="@color/blue"
android:gravity="center"
android:clickable="true"
android:text="Delete"
android:singleLine="true"/>
<TextView
android:id="@+id/tv_iUri"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:textSize="13sp"
android:gravity="center"
android:clickable="true"
android:visibility="gone"
android:text="Uri" />
<TextView
android:id="@+id/tv_RowId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
请帮助或建议我解决此问题的任何示例。谢谢!以下是我的自定义适配器的代码
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;
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]);
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);
});
}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();
}
}
}