如何获取列表视图的内容与列表外的一个按钮 [英] how to get the content of listview with a button outside the list

查看:102
本文介绍了如何获取列表视图的内容与列表外的一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我搜索到目前为止大约是通过将按钮的每一行中获取列表视图中的数据,但我想实现的是通过将按钮列表外挑列表视图的内容。

我已经创建了一个可编辑列表视图,其中用户输入的值,这个值将被一列相乘已经present在列表中,结果将在另一个TextView中进行设置。

现在单击按钮时(这是列表如下),我想执行以下两件事情。


  1. 我想只得到那些用户输入在文本框的值的行。以及


  2. 这是列表视图上面给出的editTexts(姓名和地址)的值。并保存他们的SQLite。


我不知道如何做到这一点,任何帮助将大大AP preciated。很抱歉,如果我不清楚。
下面是我的ListView适配器的code

  @覆盖
公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){
  最后ViewHolder持有人;
  如果(convertView == NULL){
        convertView = inflater.inflate(R.layout.productslistviewadapter,父母,假);        持有人=新ViewHolder();
        holder.tvdr code =(TextView中)convertView.findViewById(R.id.tvname);
        holder.tvDrName =(TextView中)convertView.findViewById(R.id.tvprodpack);
        holder.tvterr code =(TextView中)convertView.findViewById(R.id.textView3);
        holder.caption =(EditText上)convertView.findViewById(R.id.editText1);
        holder.tvValue =(TextView中)convertView.findViewById(R.id.value);
        holder.tvValue.setVisibility(View.GONE);
        convertView.setTag(保持器);    }
 其他{
        支架=(ViewHolder)convertView.getTag();
    }    产品P = prodList.get(位置);
    holder.tvdr code.setText(p.getDoc code());
    holder.tvDrName.setText(p.getDocName());
    holder.tvterr code.setText(p.getAdr());    //为EDITTEXT
    holder.caption.setTag(位置);
    holder.caption.setText(p.getCaption());
    INT tag_position =(整数)holder.caption.getTag();
    holder.caption.setId(tag_position);    holder.caption.setOnFocusChangeListener(新View.OnFocusChangeListener(){
        公共无效onFocusChange(视图V,布尔hasFocus){
           如果(!hasFocus){
               / *
             *丢失焦点时节省输入值
             *以后使用
             * /
               INT位置2;
               情况2 = holder.caption.getId();
               情况2 = holder.tvValue.getId();
               最终的EditText标题=(EditText上)holder.caption;
               最终的TextView TvValue =(TextView中)holder.tvValue;               如果(Caption.getText()的toString()长度()方式> 0)
                 {
                   prodList.get(位置2).setCaption(Caption.getText()的toString());                   。字符串PRODPACK = prodList.get(位置).getDocName()的toString();
                   字符串PRODNAME = prodList.get(位置).getDoc code()的toString()。
                   串数量= prodList.get(位置2).getCaption()                   int值=的Integer.parseInt(PRODPACK)*的Integer.parseInt(数量);
                   holder.tvValue.setText(Integer.toString(值));
                   holder.tvValue.setVisibility(View.VISIBLE);               }
               其他{
                    Log.e(输入一些价值,是);
               }             }
        }
    });


解决方案

尝试下面的点击按钮code段

 的for(int i = 0; I< listView.getAdapter()getCount将();我++){
            产品POLD =(产品)listView.getAdapter()的getItem(我)。
            产品Pnew最多= prodlist.get(ⅰ);
            如果(pold.getCaption()!= NULL)
            {
             如果(pold.getCaption()!= pnew.getCaption()。的toString())
             {
              //调用sqlite的保存位置
              Log.d(是,是);
             }
             其他{
              Log.d(否,否);
             }
            }

希望这有助于

Whatever I searched so far is about getting the list view data by placing the button in each row, But what I want to achieve is to pick the listview content by placing the button outside the list.

I have created an editable listview where user will enter the value and this value will be multiplied by one of the columns already present in the list and the result will be set in another textview.

Now on clicking the button (which is given below the list)I want to perform the following two things.

  1. I want to get only those rows where user has entered the values in the textboxes. and

  2. the values of the editTexts (name and address) which are given above the listview. and saves them to sqlite.

I don't know how to do this, any help would be greatly appreciated. Sorry if I'm not clear. Below is the code of my listview adapter

@Override
public View getView( final int position, View convertView, ViewGroup parent)   {        
  final   ViewHolder holder;
  if (convertView == null) {
        convertView = inflater.inflate(R.layout.productslistviewadapter, parent, false);

        holder = new ViewHolder();
        holder.tvdrCode = (TextView) convertView.findViewById(R.id.tvname);
        holder.tvDrName = (TextView) convertView.findViewById(R.id.tvprodpack);
        holder.tvterrcode= (TextView) convertView.findViewById(R.id.textView3);
        holder.caption = (EditText)convertView.findViewById(R.id.editText1);
        holder.tvValue = (TextView) convertView.findViewById(R.id.value);
        holder.tvValue.setVisibility(View.GONE);
        convertView.setTag(holder);

    } 
 else {
        holder = (ViewHolder) convertView.getTag();
    }

    Products p = prodList.get(position);
    holder.tvdrCode.setText(p.getDocCode());
    holder.tvDrName.setText(p.getDocName());
    holder.tvterrcode.setText(p.getAdr());

    //for editText
    holder.caption.setTag(position);
    holder.caption.setText(p.getCaption());
    int tag_position=(Integer) holder.caption.getTag();
    holder.caption.setId(tag_position); 

    holder.caption.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
           if (!hasFocus) {
               /*
             * When focus is lost save the entered value for
             * later use
             */
               int position2; 
               position2 = holder.caption.getId();
               position2 = holder.tvValue.getId();
               final EditText Caption = (EditText) holder.caption;
               final TextView TvValue = (TextView) holder.tvValue;

               if(Caption.getText().toString().length()>0)
                 {
                   prodList.get(position2).setCaption(Caption.getText().toString());

                   String prodpack = prodList.get(position).getDocName().toString();
                   String prodname = prodList.get(position).getDocCode().toString();
                   String quantity = prodList.get(position2).getCaption()

                   int  value = Integer.parseInt(prodpack) * Integer.parseInt(quantity);   
                   holder.tvValue.setText(Integer.toString(value)); 
                   holder.tvValue.setVisibility(View.VISIBLE);

               }  
               else{
                    Log.e("enter some value", "yes");
               }

             }
        }
    });     

解决方案

Try the below code snippet on the button click

for (int i = 0; i < listView.getAdapter().getCount(); i++) {
            Products pold = (Products) listView.getAdapter().getItem(i);
            Products pnew = prodlist.get(i);         
            if(pold.getCaption() !=null)
            {
             if(pold.getCaption() != pnew.getCaption().toString())
             {
              //Call sqlite save here
              Log.d("yes", "yes");
             }
             else {
              Log.d("no", "no");
             }   
            }

Hope this helps

这篇关于如何获取列表视图的内容与列表外的一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆