Android 单击后在自定义listview中修改textview值

Android 单击后在自定义listview中修改textview值,android,Android,此listview有一个适配器,该适配器链接到每行的布局(itemrow.xml) 价格值(500-250 300)是文本视图 我们如何访问它,修改它,一旦点击一个按钮 llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll public class CommandeAdapter

此listview有一个适配器,该适配器链接到每行的布局(itemrow.xml)

价格值(500-250 300)是文本视图

我们如何访问它,修改它,一旦点击一个按钮

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

public class CommandeAdapter extends BaseAdapter implements OnClickListener {
private Context context;

private List<Commande> listCommande;

public CommandeAdapter(Context context, List<Commande> listCommande) {
    this.context = context;
    this.listCommande = listCommande;
}

public int getCount() {
    return listCommande.size();
}

public Object getItem(int position) {
    return listCommande.get(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup viewGroup) {
    Commande entry = listCommande.get(position);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.listitem_row, null);
    }
    TextView tvNom = (TextView) convertView.findViewById(R.id.textView1);
    tvNom.setText(entry.getNom());

    TextView tvPrixU = (TextView) convertView.findViewById(R.id.textView2);
    tvPrixU.setText(entry.getPrixU());

    TextView tvqte = (TextView) convertView.findViewById(R.id.textView4);
    tvqte.setText(entry.getQte());

    TextView tvSomme = (TextView) convertView.findViewById(R.id.textView5);
    tvSomme.setText(String.format("%.03f", entry.getSomme()));

    return convertView;
}

@Override
public void onClick(View view) {
    Commande entry = (Commande) view.getTag();
    listCommande.remove(entry);
    // listCommande.remove(view.getId());
    notifyDataSetChanged();

}

private void showDialog(Commande entry) {
    // Create and show your dialog
    // Depending on the Dialogs button clicks delete it or do nothing
}
安卓

价格:500

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

public class CommandeAdapter extends BaseAdapter implements OnClickListener {
private Context context;

private List<Commande> listCommande;

public CommandeAdapter(Context context, List<Commande> listCommande) {
    this.context = context;
    this.listCommande = listCommande;
}

public int getCount() {
    return listCommande.size();
}

public Object getItem(int position) {
    return listCommande.get(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup viewGroup) {
    Commande entry = listCommande.get(position);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.listitem_row, null);
    }
    TextView tvNom = (TextView) convertView.findViewById(R.id.textView1);
    tvNom.setText(entry.getNom());

    TextView tvPrixU = (TextView) convertView.findViewById(R.id.textView2);
    tvPrixU.setText(entry.getPrixU());

    TextView tvqte = (TextView) convertView.findViewById(R.id.textView4);
    tvqte.setText(entry.getQte());

    TextView tvSomme = (TextView) convertView.findViewById(R.id.textView5);
    tvSomme.setText(String.format("%.03f", entry.getSomme()));

    return convertView;
}

@Override
public void onClick(View view) {
    Commande entry = (Commande) view.getTag();
    listCommande.remove(entry);
    // listCommande.remove(view.getId());
    notifyDataSetChanged();

}

private void showDialog(Commande entry) {
    // Create and show your dialog
    // Depending on the Dialogs button clicks delete it or do nothing
}
Php

售价:250

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

public class CommandeAdapter extends BaseAdapter implements OnClickListener {
private Context context;

private List<Commande> listCommande;

public CommandeAdapter(Context context, List<Commande> listCommande) {
    this.context = context;
    this.listCommande = listCommande;
}

public int getCount() {
    return listCommande.size();
}

public Object getItem(int position) {
    return listCommande.get(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup viewGroup) {
    Commande entry = listCommande.get(position);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.listitem_row, null);
    }
    TextView tvNom = (TextView) convertView.findViewById(R.id.textView1);
    tvNom.setText(entry.getNom());

    TextView tvPrixU = (TextView) convertView.findViewById(R.id.textView2);
    tvPrixU.setText(entry.getPrixU());

    TextView tvqte = (TextView) convertView.findViewById(R.id.textView4);
    tvqte.setText(entry.getQte());

    TextView tvSomme = (TextView) convertView.findViewById(R.id.textView5);
    tvSomme.setText(String.format("%.03f", entry.getSomme()));

    return convertView;
}

@Override
public void onClick(View view) {
    Commande entry = (Commande) view.getTag();
    listCommande.remove(entry);
    // listCommande.remove(view.getId());
    notifyDataSetChanged();

}

private void showDialog(Commande entry) {
    // Create and show your dialog
    // Depending on the Dialogs button clicks delete it or do nothing
}
C++

价格:300

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

public class CommandeAdapter extends BaseAdapter implements OnClickListener {
private Context context;

private List<Commande> listCommande;

public CommandeAdapter(Context context, List<Commande> listCommande) {
    this.context = context;
    this.listCommande = listCommande;
}

public int getCount() {
    return listCommande.size();
}

public Object getItem(int position) {
    return listCommande.get(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup viewGroup) {
    Commande entry = listCommande.get(position);
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.listitem_row, null);
    }
    TextView tvNom = (TextView) convertView.findViewById(R.id.textView1);
    tvNom.setText(entry.getNom());

    TextView tvPrixU = (TextView) convertView.findViewById(R.id.textView2);
    tvPrixU.setText(entry.getPrixU());

    TextView tvqte = (TextView) convertView.findViewById(R.id.textView4);
    tvqte.setText(entry.getQte());

    TextView tvSomme = (TextView) convertView.findViewById(R.id.textView5);
    tvSomme.setText(String.format("%.03f", entry.getSomme()));

    return convertView;
}

@Override
public void onClick(View view) {
    Commande entry = (Commande) view.getTag();
    listCommande.remove(entry);
    // listCommande.remove(view.getId());
    notifyDataSetChanged();

}

private void showDialog(Commande entry) {
    // Create and show your dialog
    // Depending on the Dialogs button clicks delete it or do nothing
}
公共类CommandeApter扩展BaseAdapter实现OnClickListener{
私人语境;
私有列表命令;
公共命令dapter(上下文上下文,列表命令){
this.context=上下文;
this.listCommande=listCommande;
}
public int getCount(){
返回listCommande.size();
}
公共对象getItem(int位置){
返回listCommande.get(位置);
}
公共长getItemId(int位置){
返回位置;
}
公共视图getView(int位置、视图转换视图、视图组视图组){
Commande entry=listCommande.get(位置);
if(convertView==null){
LayoutFlater充气器=(LayoutFlater)上下文
.getSystemService(上下文布局\充气机\服务);
convertView=充气机。充气(R.layout.listitem_行,空);
}
TextView tvNom=(TextView)convertView.findViewById(R.id.textView1);
setText(entry.getNom());
TextView tvPrixU=(TextView)convertView.findViewById(R.id.textView2);
setText(entry.getPrixU());
TextView tvqte=(TextView)convertView.findViewById(R.id.textView4);
setText(entry.getQte());
TextView-tvsome=(TextView)convertView.findViewById(R.id.textView5);
setText(String.format(“%.03f”,entry.getSomme());
返回视图;
}
@凌驾
公共void onClick(视图){
Commande entry=(Commande)view.getTag();
删除(条目);
//remove(view.getId());
notifyDataSetChanged();
}
私有void显示对话框(命令条目){
//创建并显示对话框
//根据对话框按钮,单击“删除”或“不执行任何操作”
}

}

是的,可以通过覆盖自定义适配器的getView()函数更新textview上的内容。在这里发布adpater、itemrow.xml和主xml。