Hello,
i'm trying to edit the text on a edittext that is part of a item in a ListView.
When i write something and scroll down the text dissapears.
What is the solution based in the bellow code?
The main activity when button is clicked
-------------------------------------
String[] dados=artigos_selecionados.split(";#");
final ListView lv=(ListView)findViewById(R.id.listView);
ArrayList<OrcamentosHeaderClass> artigoslist=new ArrayList<OrcamentosHeaderClass>();
OrcamentosHeaderAdapter adapter= new OrcamentosHeaderAdapter(this,R.layout.layout_artigos_orcamentos);
lv.setAdapter(adapter);
lv.setEnabled(true);
for (int i=0 ; i<dados.length;i++){
System.out.println(dados);
String[] artigos=dados.split(";");
//ref,descricao,valor,quant
if (artigos[0]!=null){
String empresajuncao=artigos[0] +" - " + artigos[1];
String artigotratado=artigos[5].replace("Stock:","").replace("und","").replace(" ","");
OrcamentosHeaderClass obj=new OrcamentosHeaderClass(empresajuncao, artigos[2],artigos[3],artigotratado,artigos[4],artigos[6]);
adapter.add(obj);
adapter .notifyDataSetChanged();
}
}
---------------------------------
The Adapter
-------------------------------------------------------
public class OrcamentosHeaderAdapter extends android.widget.ArrayAdapter {
public List<DadosHolder> myItems;
private Integer count;
public OrcamentosHeaderAdapter(Context ctx, int resource){
super(ctx,resource);
}
@override
public View getView(int position, final View convertView, ViewGroup parent) {
View row=convertView;
final DadosHolder holder;
if(convertView==null){
LayoutInflater inflater=(LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.layout_artigos_orcamentos ,parent,false);
holder=new DadosHolder();
holder.ref=(TextView)row.findViewById(R.id.tv_ref_artigo);
holder.descricao=(TextView)row.findViewById(R.id.tv_descricao_artigo);
holder.valor=(TextView)row.findViewById(R.id.tv_precounit);
holder.quant=(EditText)row.findViewById(R.id.tb_quant);
holder.relacionado=(TextView)row.findViewById(R.id.tv_assoc);
holder.empresa=(TextView)row.findViewById(R.id.tv_empresa_artigo);
holder.precofinal=(TextView)row.findViewById(R.id.tv_precofinal);
row.setTag(holder);
}else {
holder=(DadosHolder) row.getTag();
}
OrcamentosHeaderClass orcamentosHeaderClass = (OrcamentosHeaderClass) getItem(position);
count=position;
System.out.println("POS" + count);
holder.ref.setText(orcamentosHeaderClass.getRef());
holder.descricao.setText(orcamentosHeaderClass.getDescricao());
holder.valor.setText(orcamentosHeaderClass.getValor() +"€");
holder.quant.setText(orcamentosHeaderClass.getQuant());
holder.relacionado.setText(orcamentosHeaderClass.getRelacionado());
holder.empresa.setText(orcamentosHeaderClass.getEmpresa());
holder.quant.addTextChangedListener(new TextWatcher() {
@override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@override
public void onTextChanged(CharSequence s, int start, int before, int count) {
System.out.println("Text "+ holder.quant.getText().toString());
}
@override
public void afterTextChanged(Editable s) {
}
});
holder.quant.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
final int position = v.getId();
final EditText Caption=(EditText)convertView.findViewById(position);
System.out.println("Text "+ Caption.getText().toString());
//myItems.get(position).setQuant( Caption.getText().toString());
holder.quant.setText(Caption.getText().toString());
}
}
});
return row;
}
class DadosHolder{
TextView ref;
TextView descricao;
TextView valor;
EditText quant;
TextView relacionado;
TextView empresa;
TextView precofinal;
}
@override
public int getCount() {
//count= getCount();
return super.getCount();
//return myItems.size();
}
@override
public long getItemId(int position) {
return super.getItemId(position);
}
}
---------------------------
The Class
-------------------------------
public class OrcamentosHeaderClass{
private String ref;
private String descricao;
private String valor;
String quant;
private String relacionado;
private String empresa;
public OrcamentosHeaderClass(String empresa,String ref,String descricao,String quant,String valor,String assoc){
super();
this.setDescricao(descricao);
this.setRef(ref);
this.setEmpresa(empresa);
this.setQuant(quant);
this.setRelacionado(assoc);
this.setValor(valor);
}
public String getRef() {
return ref;
}
public String getDescricao() {
return descricao;
}
public String getValor() {
return valor;
}
public String getQuant() {
return quant;
}
public String getRelacionado() {
return relacionado;
}
public String getEmpresa() {
return empresa;
}
public void setRef(String ref) {
this.ref = ref;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public void setValor(String valor) {
this.valor = valor;
}
public void setQuant(String quant) {
this.quant = quant;
}
public void setRelacionado(String relacionado) {
this.relacionado = relacionado;
}
public void setEmpresa(String empresa) {
this.empresa = empresa;
}
-----------------
That's all the related code..
If you need anything please tell me.
Thanks!
i'm trying to edit the text on a edittext that is part of a item in a ListView.
When i write something and scroll down the text dissapears.
What is the solution based in the bellow code?
The main activity when button is clicked
-------------------------------------
String[] dados=artigos_selecionados.split(";#");
final ListView lv=(ListView)findViewById(R.id.listView);
ArrayList<OrcamentosHeaderClass> artigoslist=new ArrayList<OrcamentosHeaderClass>();
OrcamentosHeaderAdapter adapter= new OrcamentosHeaderAdapter(this,R.layout.layout_artigos_orcamentos);
lv.setAdapter(adapter);
lv.setEnabled(true);
for (int i=0 ; i<dados.length;i++){
System.out.println(dados);
String[] artigos=dados.split(";");
//ref,descricao,valor,quant
if (artigos[0]!=null){
String empresajuncao=artigos[0] +" - " + artigos[1];
String artigotratado=artigos[5].replace("Stock:","").replace("und","").replace(" ","");
OrcamentosHeaderClass obj=new OrcamentosHeaderClass(empresajuncao, artigos[2],artigos[3],artigotratado,artigos[4],artigos[6]);
adapter.add(obj);
adapter .notifyDataSetChanged();
}
}
---------------------------------
The Adapter
-------------------------------------------------------
public class OrcamentosHeaderAdapter extends android.widget.ArrayAdapter {
public List<DadosHolder> myItems;
private Integer count;
public OrcamentosHeaderAdapter(Context ctx, int resource){
super(ctx,resource);
}
@override
public View getView(int position, final View convertView, ViewGroup parent) {
View row=convertView;
final DadosHolder holder;
if(convertView==null){
LayoutInflater inflater=(LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.layout_artigos_orcamentos ,parent,false);
holder=new DadosHolder();
holder.ref=(TextView)row.findViewById(R.id.tv_ref_artigo);
holder.descricao=(TextView)row.findViewById(R.id.tv_descricao_artigo);
holder.valor=(TextView)row.findViewById(R.id.tv_precounit);
holder.quant=(EditText)row.findViewById(R.id.tb_quant);
holder.relacionado=(TextView)row.findViewById(R.id.tv_assoc);
holder.empresa=(TextView)row.findViewById(R.id.tv_empresa_artigo);
holder.precofinal=(TextView)row.findViewById(R.id.tv_precofinal);
row.setTag(holder);
}else {
holder=(DadosHolder) row.getTag();
}
OrcamentosHeaderClass orcamentosHeaderClass = (OrcamentosHeaderClass) getItem(position);
count=position;
System.out.println("POS" + count);
holder.ref.setText(orcamentosHeaderClass.getRef());
holder.descricao.setText(orcamentosHeaderClass.getDescricao());
holder.valor.setText(orcamentosHeaderClass.getValor() +"€");
holder.quant.setText(orcamentosHeaderClass.getQuant());
holder.relacionado.setText(orcamentosHeaderClass.getRelacionado());
holder.empresa.setText(orcamentosHeaderClass.getEmpresa());
holder.quant.addTextChangedListener(new TextWatcher() {
@override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@override
public void onTextChanged(CharSequence s, int start, int before, int count) {
System.out.println("Text "+ holder.quant.getText().toString());
}
@override
public void afterTextChanged(Editable s) {
}
});
holder.quant.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
final int position = v.getId();
final EditText Caption=(EditText)convertView.findViewById(position);
System.out.println("Text "+ Caption.getText().toString());
//myItems.get(position).setQuant( Caption.getText().toString());
holder.quant.setText(Caption.getText().toString());
}
}
});
return row;
}
class DadosHolder{
TextView ref;
TextView descricao;
TextView valor;
EditText quant;
TextView relacionado;
TextView empresa;
TextView precofinal;
}
@override
public int getCount() {
//count= getCount();
return super.getCount();
//return myItems.size();
}
@override
public long getItemId(int position) {
return super.getItemId(position);
}
}
---------------------------
The Class
-------------------------------
public class OrcamentosHeaderClass{
private String ref;
private String descricao;
private String valor;
String quant;
private String relacionado;
private String empresa;
public OrcamentosHeaderClass(String empresa,String ref,String descricao,String quant,String valor,String assoc){
super();
this.setDescricao(descricao);
this.setRef(ref);
this.setEmpresa(empresa);
this.setQuant(quant);
this.setRelacionado(assoc);
this.setValor(valor);
}
public String getRef() {
return ref;
}
public String getDescricao() {
return descricao;
}
public String getValor() {
return valor;
}
public String getQuant() {
return quant;
}
public String getRelacionado() {
return relacionado;
}
public String getEmpresa() {
return empresa;
}
public void setRef(String ref) {
this.ref = ref;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public void setValor(String valor) {
this.valor = valor;
}
public void setQuant(String quant) {
this.quant = quant;
}
public void setRelacionado(String relacionado) {
this.relacionado = relacionado;
}
public void setEmpresa(String empresa) {
this.empresa = empresa;
}
-----------------
That's all the related code..
If you need anything please tell me.
Thanks!