即時通訊嘗試保存在ListView中的Edittext的值,它的工作原理,但是當ListView過大,當我編輯1編輯文本,如果我滾動列表視圖,另一個EditText正在編輯同時......我不知道該怎麼做,我浪費了6小時,什麼都沒有。如果有人能幫助我,請。如何使用edittexts在自定義ListView中實現監聽器文本更改?
這是自定義列表視圖
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int position2 = position;
View v = convertView;
final ViewHolder holder;
if(v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.lista_item_prepedido, null);
holder = new ViewHolder();
holder.codi = (TextView) v.findViewById(R.id.NomProducte);
holder.nom = (EditText) v.findViewById(R.id.Preu);
holder.eliminar = (ImageButton) v.findViewById(R.id.delete);
View eliminarPrepedido = (ImageButton) v.findViewById(R.id.delete);
if(blocClients.equals("0"))
{
eliminarPrepedido.setVisibility(View.GONE);
holder.nom.setFocusable(false);
}
v.setTag(holder);
holder.nom.setText(items.get(position).getNom());
holder.nom.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
items.get(position2).Nom = s.toString();
String preu = items.get(position2).Nom;
String nomproducte = items.get(position2).Codic;
int position = position2;
//mostrarMensaje("Valor: "+preu+" Nom Producte: "+nomproducte+" CodiClient: " +CodicClient+ " posicio: "+position);
baseDatos = openOrCreateDatabase(nombreBD, MODE_WORLD_WRITEABLE, null);
String sqlStr = "UPDATE estadistiques SET ultimpreu = '" +preu+"' WHERE codic_client='"+CodicClient+"' AND desc_article = '"+nomproducte+"' ";
baseDatos.execSQL(sqlStr);
try {
fnGlobal.CreaSincroFitxer(sqlStr);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
baseDatos.close();
}
});
} else {
holder = (ViewHolder) v.getTag();
}
holder.codi.setText(items.get(position).getCodic());
holder.eliminar.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final int position = position2;
String CodicClient = null;
Bundle extras = getIntent().getExtras();
CodicClient = extras.getString("codiClientTab");
String nomproducte = items.get(position).Codic;
int Opcio = 1;
baseDatos = openOrCreateDatabase(nombreBD, MODE_WORLD_WRITEABLE, null);
String sqlStr = "DELETE FROM estadistiques WHERE codic_client ='"+CodicClient+"' AND desc_article ='"+nomproducte+"'" ;
baseDatos.execSQL(sqlStr);
try {
fnGlobal.CreaSincroFitxer(sqlStr);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
baseDatos.close();
notifyDataSetChanged();
onResume();
}
});
return v;
}
}
的getView的代碼
的列表視圖
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="@drawable/rounded_rectangle"
android:orientation="horizontal"
android:padding="6dip" >
<ImageButton
android:id="@+id/delete"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="6dp"
android:layout_marginTop="15dp"
android:background="@drawable/delete" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="@+id/Preu"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/NomProducte"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="@color/white"
android:ellipsize="end"
android:gravity="right"
android:inputType="numberDecimal"
android:singleLine="true"
android:text="nom"
android:textSize="18sp" />
<TextView
android:id="@+id/NomProducte"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/Preu"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_weight="0.16"
android:clickable="false"
android:ellipsize="end"
android:focusable="false"
android:focusableInTouchMode="false"
android:singleLine="true"
android:text="codi"
android:textColor="#000000"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
自定義XML項目
非常感謝! :)
您可以添加R.layout.lista_item_prepedido中的代碼,以便清楚自定義ListView中的內容 - 它可以幫助人們回答。 – 2013-03-14 11:56:30
更新了R.layout.item_item_prepedido – Ezrou 2013-03-15 08:21:32