1
我有問題從編輯文本里面的listview裏面,當im在最後一次edittext中獲取該數據的edittext的問題,因爲當該edittext的焦點onfocuschangelistner沒有得到調用和該edittext的數據不存儲在我的集合變量。Android:如何從ListView中的Edittext獲取文本?
所以任何一個有任何解決方案PLZ建議我
我的代碼是在這裏
public class YourAdapter extends SimpleAdapter {
protected static final String TAG = null;
ArrayList<HashMap<String, String>> c = new ArrayList<HashMap<String, String>>();
Context context;
JSONArray getArray_Meter_Reading;
HashMap<String, String> previous_Meter_Reading;
ArrayList<HashMap<String, Integer>> getReading = new ArrayList<HashMap<String, Integer>>();
Map<String,Integer> CurrentReading = new HashMap<String, Integer>();
int i, previousMeterReading, CurrentMeterReading, Cumulative;
View v;
EditText Caption;
public static HashMap<Integer, String> myList = new HashMap<Integer, String>();
public YourAdapter(Context context, int layout,
ArrayList<HashMap<String, String>> c, String[] from, int[] to,
JSONArray getArray_Meter_Reading) {
super(context, c, layout, from, to);
this.c = c;
this.context = context;
this.v = null;
this.Caption = null;
this.getArray_Meter_Reading = getArray_Meter_Reading;
for (i = 0; i < getArray_Meter_Reading.length(); i++) {
myList.put(i, "");
}
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
final EditText ed_Current = (EditText) view
.findViewById(R.id.ed_Current);
ed_Current.setTag(position);
ed_Current.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View arg0, boolean arg1) {
int tag1 = (Integer) arg0.getTag();
myList.put(tag1, ed_Current.getText().toString().trim());
previous_Meter_Reading = new HashMap<String, String>();
if (v == null) {
v = arg0;
int tag = (Integer) arg0.getTag();
Caption = (EditText) arg0;
previous_Meter_Reading = c.get(tag);
String getPreviousReading = previous_Meter_Reading
.get("previousMeterReading");
String CumulativeIndex = previous_Meter_Reading
.get("Cumulative");
previousMeterReading = Integer.parseInt(getPreviousReading);
Cumulative = Integer.parseInt(CumulativeIndex);
}
if (v != arg0) {
if (!Caption.getText().toString().equals("")
&& Cumulative == 1) {
int tag = ((Integer) arg0.getTag());
CurrentMeterReading = Integer.valueOf(Caption.getText()
.toString());
//CurrentReading.put("Tag"+ tag, CurrentMeterReading);
//if(CurrentReading.containsKey("Tag"+ tag)){
//
// Log.d("Contains","Tag"+ tag);
// CurrentReading.remove("Tag"+ tag);
//}
// }else{
//
CurrentReading.put("Tag"+ tag,CurrentMeterReading);
//}
//getReading.add(CurrentReading);
Log.d("CurrentReading",CurrentReading.toString());
if (CurrentMeterReading < previousMeterReading) {
AlertDialog.Builder builder = new AlertDialog.Builder(
context);
builder.setTitle("WARNING");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setMessage("Current value cannot be less than Previous value for metre");
builder.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {
//Caption.requestFocus();
}
});
AlertDialog diag = builder.create();
diag.show();
// Caption.requestFocus();
// v = null;
// Caption = null;
}
}else {
if (Cumulative == 0
&& !Caption.getText().toString().equals("")) {
int tag = ((Integer) arg0.getTag());
// int tag1 = ((Integer) arg0.getTag());
CurrentMeterReading = Integer.valueOf(Caption
.getText().toString());
CurrentReading.put("Tag" +tag, CurrentMeterReading);
if(CurrentReading.containsKey("Tag"+ tag)){
CurrentReading.put("Tag"+ tag,CurrentMeterReading);
}
//getReading.add(CurrentReading);
}
}
//Caption.requestFocus();
v = null;
Caption = null;
}
}
});
ed_Current.setText(myList.get(position));
return view;
}
}
and my xml which im binding with listview using simpleadapter
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="6dip"
android:paddingTop="4dip" >
<TextView
android:id="@+id/txt_Meter_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:width="140dp" />
<TextView
android:id="@+id/txt_Previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:width="100dp" />
<EditText
android:id="@+id/ed_Current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:imeOptions="actionNext|actionDone"
android:inputType="number"
android:numeric="integer"
android:singleLine="true"
android:width="100dp" >
</EditText>
</LinearLayout>
在此先感謝