Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 随机列表查看更改项_Java_Android_Listview_Conflict - Fatal编程技术网

Java 随机列表查看更改项

Java 随机列表查看更改项,java,android,listview,conflict,Java,Android,Listview,Conflict,我有一个列表视图,当我用点击加号按钮改变一个项目(计数)的值时,只要用户向下滚动并显示更多项目,一切都很好 我们看到在卷轴的每一页上都改变了item的值!!! 我不知道为什么一切看起来都很好 public class MyAdapter extends BaseAdapter { private String[] from; ArrayList <HashMap<String, Object>> BuyList ; private int[

我有一个列表视图,当我用点击加号按钮改变一个项目(计数)的值时,只要用户向下滚动并显示更多项目,一切都很好 我们看到在卷轴的每一页上都改变了item的值!!! 我不知道为什么一切看起来都很好

public class MyAdapter extends BaseAdapter  {

    private  String[] from;
    ArrayList <HashMap<String, Object>> BuyList ;
    private  int[] to;
    private Context context;
    private  ArrayList<HashMap<String, Object>> data ;
    private  ArrayList<HashMap<String, Object>> selecteddata;
    private  ArrayList<HashMap<String, Object>> fdata ;
    private  ImageView pay,more;
    private  EditText search;
    private  String user_mobile;
    private  TextView buy_toolbar_count;
    private Holder holder;
   // private HashMap<String, Object> hm;

    public MyAdapter( Context context, ArrayList<HashMap<String, Object>> data,
                      ArrayList<HashMap<String, Object>> selecteddata , String[] from, int[] to, ArrayList Bylist,
                      ImageView pay, ImageView more, String user_mobile, TextView buy_count_toolbar, EditText search) {
        this.data = data;
        this.selecteddata = selecteddata;
        this.fdata = new ArrayList<>(selecteddata);

        this.context = context;
        this.from  = from;
        this.to  = to;
        this.BuyList = Bylist;
        this.pay = pay;
        this.more = more;
        this.search = search;
        this.user_mobile = user_mobile;
        this.buy_toolbar_count = buy_count_toolbar;

    }


    public  void filter(String s, ImageView img) {
        HashMap<String, Object> wp = new HashMap<>();

        if (!s.equals("")) {

            fdata.clear();
            for (int i = 0 ;i<data.size();i++) {
                wp = data.get(i);
                // Log.i("mosi",wp.get("name").toString() + " wp  ");

                if (wp.get("name").toString().toLowerCase().contains(s)) {


                    fdata.add(wp);




                }

            }

        }
        else {
            fdata = new ArrayList<>(selecteddata);

        }
        notifyDataSetChanged();
    }

    public class Holder
    {

        ImageView g_img;
        ImageView plus;
        ImageView mines;
        TextView g_name;
        TextView g_price;
        TextView g_off;
        TextView count;
        TextView f_range;
        TextView sum;
        TextView temp2;
    }
   @Override
    public int getCount() {
        return fdata.size();
    }

    @Override
    public HashMap<String, Object> getItem(int i) {
        return fdata.get(i);
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }
    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {


        Typeface font_titr = Typeface.createFromAsset(context.getAssets(), "fonts/titr.TTF");
        final HashMap<String, Object> hm = fdata.get(position);


        if (convertView == null ) {
            holder = new Holder();
            convertView = LayoutInflater.from(context).
                    inflate(R.layout.my_row_layout2, parent, false);

            holder.g_img = (ImageView) convertView.findViewById(R.id.f_img);
            holder.g_name = (TextView) convertView.findViewById(R.id.f_name);
            holder.g_price = (TextView) convertView.findViewById(R.id.f_price);
            holder.g_off = (TextView) convertView.findViewById(R.id.f_off);
            holder.count = (TextView) convertView.findViewById(R.id.f_count);
            holder.f_range = (TextView) convertView.findViewById(R.id.f_kilo);
            holder.plus = (ImageView) convertView.findViewById(R.id.plus_id_btn);
            holder.mines = (ImageView) convertView.findViewById(R.id.mines_id_btn);
            holder.sum = (TextView) convertView.findViewById(R.id.count_sum_id);
            holder.temp2 = (TextView) convertView.findViewById(R.id.txt2);

            //Date currentTime = Calendar.getInstance().getTime();
            convertView.setTag(holder);
 // Log.i("mosi",convertView.getTag() + "  tagfffff  " + hm.get("convertview"));



 hm.put("convertview", "1");



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

//            Log.i("mosi",convertView.getTag() + "  tag  " + hm.get("convertview"));
        }




        final View tempview = convertView;



// set font++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


        holder.g_price.setTypeface(font_titr, Typeface.NORMAL);
        holder.g_name.setTypeface(font_titr, Typeface.BOLD);
        holder.g_off.setTypeface(font_titr, Typeface.NORMAL);
        holder.count.setTypeface(font_titr, Typeface.NORMAL);
        holder.sum.setTypeface(font_titr, Typeface.NORMAL);
        holder.temp2.setTypeface(font_titr, Typeface.NORMAL);


//----------------------------------------------------------------------------------------


        // Set pre count and sum

        holder.sum.setText(" میلغ کل : " + hm.get("sum").toString() + " تومان ");
        holder.count.setText(hm.get("count").toString());




        final String oldprice = hm.get("price").toString();




        holder.g_off.setText(hm.get("off").toString());
        holder.g_name.setText(hm.get("disc").toString());
        holder.f_range.setText(hm.get("f_range").toString());
        final float f=
                (Float.valueOf(oldprice)*
                        Float.valueOf(holder.g_off.getText().toString()))/100;

        // holder.g_price.setText(" قیمت :  "+ DtoS((Float.valueOf(oldprice.toString()))-f)+" تومان ");
        holder.g_price.setText(" قیمت :  "+  oldprice +" تومان ");



        File imageFile = new  File(hm.get("image").toString());
        if(imageFile.exists()){
            holder.g_img.setImageBitmap(BitmapFactory.decodeFile(imageFile.getAbsolutePath()));
        }
        else
            holder.g_img.setImageResource(R.drawable.coming_soon);





        holder.plus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                change_count(holder, hm, "p", tempview, ChangeType.DtoS((Float.valueOf(oldprice.toString())) - f), position);

            }

        });
        holder.mines.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                change_count(holder, hm, "m", tempview , ChangeType.DtoS((Float.valueOf(oldprice.toString()))-f), position);









            }
        });


// Button Pay && More

        pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (BuyList.size() > 0) {
                    Intent intent = new Intent(context, Payment_act.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("data", BuyList);
                    intent.putExtra("all_data", data);

                    intent.putExtra("mobile", user_mobile);
                    view.getContext().startActivity(intent);
//
                } else {
                    Toast.makeText(context, "سبد خرید شما خالی است", Toast.LENGTH_LONG).show();
                }
            }
        });

        more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, Choose_act.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("blist", BuyList);
                intent.putExtra("data", data);
                intent.putExtra("mobile", user_mobile);
                view.getContext().startActivity(intent);
                //   ((Activity)context).finish();
            }
        });



// Search -------------------------------------------------------------------

        search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence s, int i, int i1, int i2) {
                //  Log.i("mosi", s+"  ---  s ***");
                //  filter(s.toString(), holder.g_img);
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });





        return convertView;

    }


// template





    // Onclick for mines and plus Button
    //@Override
    public void change_count(final  Holder holder1, HashMap<String, Object> hm_addtolist, String tag, View c_view, String oldprice, int position) {

       // Log.i("mosi", position+"  position on list ");
        String is_pack = hm_addtolist.get("is_pack").toString();
        ChangeType ch = new ChangeType();
        double temp1 = 0;
        double p_with_off = 0;

        holder = (Holder) c_view.getTag();

        String off = hm_addtolist.get("off").toString();

        String num_sum = "0";



        if (ch.stringToDouble(off)>0)
        {
            p_with_off = ch.stringToDouble(hm_addtolist.get("price_with_off").toString());
        }
        else
            p_with_off = ch.stringToDouble(oldprice.toString());




        holder.count= (TextView) c_view.findViewById(R.id.f_count);
        holder.sum = (TextView) c_view.findViewById(R.id.count_sum_id);




        if (!holder.count.getText().toString().equals("") && holder.count!= null)
            temp1 = ch.stringToDouble(holder.count.getText().toString());
        //my_alert("", temp1+"");

        if (tag.equals("p")) {
            if (is_pack.equals("1"))
                temp1 = temp1 + 1;
            else
                temp1 = temp1 + 0.5;

            //  Log.i("mosi", " ::: set 2 !!!!");
            holder.count.setText(DtoS(temp1));

            num_sum = String.format("%d", (long)(temp1 * p_with_off));


            holder.sum.setText(" میلغ کل : " + num_sum + " تومان ");

        } else if (tag.equals("m")) {


            if (is_pack.equals("1")) {
                if (temp1 > 1) {
                    temp1 = (temp1 - 1);
                    holder.count.setText(DtoS(temp1));

                    num_sum = String.format("%d", (long) (temp1 * p_with_off));
                    holder.sum.setText(" میلغ کل : " + num_sum + " تومان ");

                } else {
                    holder.count.setText("0");
                    holder.sum.setText("مبلغ کل : 0 تومان");
                    num_sum = "0";
                    BuyList.remove(hm_addtolist);
                    notifyDataSetChanged();
                    buy_toolbar_count.setText(String.valueOf(BuyList.size()));
                }

            }
            else {
                if (temp1 > 0.5) {
                    temp1 = (temp1 - 0.5);
                    holder.count.setText(DtoS(temp1));

                    num_sum = String.format("%d", (long) (temp1 * p_with_off));
                    holder.sum.setText(" میلغ کل : " + num_sum + " تومان ");

                } else {
                    holder.count.setText("0");
                    holder.sum.setText("مبلغ کل : 0 تومان");
                    num_sum = "0";
                    hm_addtolist.put("count","0");
                    hm_addtolist.put("sum","0");
                    BuyList.remove(hm_addtolist);
                    notifyDataSetChanged();
                    buy_toolbar_count.setText(String.valueOf(BuyList.size()));
                }
            }
        }



        //}

        if (!num_sum.equals("0")) {
            hm_addtolist.put("sum", num_sum);
            hm_addtolist.put("count", holder.count.getText().toString());
            boolean check = false;
            for (int i = 0; i < BuyList.size(); i++) {
                if (BuyList.get(i).get("name").toString().equals(hm_addtolist.get("name").toString())) {
                    check = true;
                    HashMap<String, Object> temp_updatelist = BuyList.get(i);
                    temp_updatelist.put("sum", num_sum);
                    temp_updatelist.put("count", holder.count.getText().toString());
                    //  BuyList.add(temp_updatelist);
         //           Log.i("mosi",  "add count "+i+"");
                    // Toast.makeText(context, "ok", Toast.LENGTH_SHORT);
                    notifyDataSetChanged();
                }
            }
            if (!check) {
  //              Log.i("mosi",  "add count to ::  "+hm_addtolist.get("name")+"");
                BuyList.add(hm_addtolist);
                buy_toolbar_count.setText(String.valueOf(BuyList.size()));
                notifyDataSetChanged();
            }

        }


        notifyDataSetChanged();
        // Log.i("mosi", BuyList.toString());

        //   clearbug( c_view);
    }






}
 private void setlist() {

        ArrayList<HashMap<String, Object>> selected_data = new ArrayList<>();

        for (int i = 0; i < all_data.size(); i++) {
            if (all_data.get(i).get("type").toString().equals(mtag)) {
                HashMap<String, Object> t = all_data.get(i);

                selected_data.add(t);
            }
        }
        //Log.i("mosi",selected_data.toString());
        EditText search = (EditText) findViewById(R.id.et_search_id);
        ImageView pay = (ImageView) findViewById(R.id.btn_pay_firstpage);
        ImageView more = (ImageView) findViewById(R.id.btn_more_firstpage);


        String[] from = {"image", "name", "price", "off"};
        int[] to = {R.id.f_img, R.id.f_name, R.id.f_price, R.id.f_off};
        final MyAdapter adb = new MyAdapter(getBaseContext(), all_data, selected_data, from, to, BuyList, pay, more, user_mobile, buyCount_toolbar, search);



    lv.setAdapter(adb);

}
公共类MyAdapter扩展了BaseAdapter{
来自的私有字符串[];
ArrayList购买列表;
私人int[]至;
私人语境;
私有数组列表数据;
private ArrayList selecteddata;
私有ArrayList fdata;
私人影像查看付费,更多;
私人编辑文本搜索;
私有字符串用户_mobile;
私有文本视图购买工具条计数;
私人持有人;
//私有HashMap-hm;
公共MyAdapter(上下文、ArrayList数据、,
ArrayList selecteddata,String[]from,int[]to,ArrayList Bylist,
ImageView付款、ImageView更多、字符串用户\手机、文本视图购买\计数\工具栏、编辑文本搜索){
这个数据=数据;
this.selecteddata=selecteddata;
this.fdata=新阵列列表(selecteddata);
this.context=上下文;
this.from=from;
这个;
this.BuyList=Bylist;
这个。支付=支付;
这个。更多=更多;
this.search=搜索;
this.user\u mobile=user\u mobile;
this.buy\u toolbar\u count=buy\u count\u toolbar;
}
公共无效筛选器(字符串s、ImageView img){
HashMap wp=新的HashMap();
如果(!s.equals(“”){
fdata.clear();
对于(int i=0;i 0){
意向意向=新意向(上下文、付款行为类)。设置标志(意向、标志、活动、新任务);
意向书。putExtra(“数据”,买方清单);
意图。putExtra(“所有数据”,数据);
意向。putExtra(“移动”,用户\移动);
view.getContext().startActivity(intent);
//
}否则{
Toast.makeText(上下文“Toast.LENGTH”).show();
}
}
});
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
Intent Intent=newintent(上下文,选择动作类)。setFlags(Intent.FLAG\u活动\u新任务);
意向书。putExtra(“blist”,买方清单);
意向。额外(“数据”,数据);
意向。putExtra(“移动”,用户\移动);
view.getContext().startActivity(intent);
//((活动)上下文).finish();
}
});
//搜寻-------------------------------------------------------------------
search.addTextChangedListener(新的TextWatcher(){
@凌驾
更改前的公共无效(CharSequence CharSequence,int i,int i1,int i2){
}
@凌驾
public void onTextChanged(字符序列s、int i、int i1、int i2){
//Log.i(“mosi”,s+“--s***”);
//过滤器(s.toString(),holder.g_img);
}
@凌驾
public void PostTextChanged(可编辑){
}
});
返回视图;
}
//模板
//矿山和加号按钮的Onclick
//@凌驾
公共无效更改计数(最终持有者持有者1、HashMap hm_addtolist、字符串标记、视图c_视图、字符串oldprice、整数位置){
//Log.i(“mosi”,位置+“列表上的位置”);
字符串is_pack=hm_addtolist.get(“is_pack”).toString();
ChangeType ch=新的ChangeType();
双temp1=0;
双p_和_off=0;
holder=(holder)c_view.getTag();
String off=hm_addtolist.get(“off”).toString();
字符串num_sum=“0”;
如果(通道stringToDouble(关闭)>0)
{
p_with_off=ch.stringToDouble(hm_addtolist.get(“price_with_off”).toString());
}
其他的
p_with_off=ch.stringToDouble(oldprice.toString());
holder.count=(TextView)c_view.findViewById(R.id.f_count);
holder.sum=(TextView)c_view.findViewById(R.id.count_sum_id);
如果(!holder.count.getText().toString().equals(“”&&holder.count!=null)
temp1=ch.stringToDouble(holder.count.getText().toString());
//我的警报(“,temp1+”);
如果(标记为等于(“p”)){
如果(等于(“1”))
temp1=temp1+1;
其他的
temp1=temp1+0.5;
//Log.i(“mosi”,“set 2!!!!”);
holder.count.setText(DtoS(temp1));
num_sum=String.format(“%d”,长)(temp1*p_带_off));
持有人。金额。设定文本(“金额”):+num_sum+“金额”);
}else if(标记等于(“m”)){
如果(等于(“1”)){
如果(temp1>1){
temp1=(temp1-1);
holder.count.setText(DtoS(temp1));
num_sum=String.format(“%d”,长)(temp1*p_带_off));
持有人。金额。设定文本(“金额”):+num_sum+“金额”);
}否则{
持有人.count.setText(“0”);
持有人。金额。设定文本(“0”);
num_sum=“0”;
购买清单。删除(hm_addtolist);
notifyDataSetChanged();
buy_toolbar_count.setText(String.valueOf(BuyList.size());
}
}
否则{
如果(temp1>0.5){
temp1=(temp1-0.5);
holder.count.setText(DtoS(temp1));
num_sum=String.format(“%d”,长)(temp1*p_带_off));
持有人。金额。设定文本(“金额”):+num_sum+“金额”);
}否则{
持有人.count.setText(“0”);
持有人
    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutDirection="rtl"
    android:background="@drawable/main_background_theme">

    <include
        android:id="@+id/mytoolbar"
        layout="@layout/toolbar"
        android:layout_height="?attr/actionBarSize"
        android:layout_width="match_parent"/>
    <include
        android:id="@+id/app_message"
        layout="@layout/message"
        android:layout_height="30dp"
        android:layout_width="match_parent"
        android:layout_below="@+id/mytoolbar"/>

    <include
        android:id="@+id/searchbox_id"
        layout="@layout/searchbox"
        android:layout_height="40sp"
        android:layout_width="match_parent"
        android:layout_below="@+id/app_message"
        android:visibility="invisible"/>

<android.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/searchbox_id"

    android:id="@+id/FirstPage_id">



<RelativeLayout
    android:id="@+id/rv_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainLayoutActivity">

    <ListView
        android:id="@+id/my_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@color/listDivader"
        android:dividerHeight="1dp"
        android:paddingBottom="?attr/actionBarSize" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignBottom="@id/my_listview"
        android:background="@color/toolbar_back"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/btn_pay_firstpage"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="50"
            android:paddingLeft="10sp"

            android:src="@drawable/btn_pay" />

        <ImageView
            android:id="@+id/btn_more_firstpage"
            android:layout_width="0px"
            android:layout_height="match_parent"
            android:layout_weight="50"

            android:paddingLeft="10sp"
            android:src="@drawable/btn_more" />


    </LinearLayout>
</RelativeLayout>

<fragment
    android:layout_width="180dp"
    android:layout_height="match_parent"
    android:id="@+id/drawer_fragment"
    android:layout_gravity="start"
    android:layout="@layout/drawer_fragment_layout"
    tools:layout="@layout/drawer_fragment_layout"
    android:name="com.com.seyedi89gmail.sm.zanco.Drawer_fragment">

</fragment>


</android.support.v4.widget.DrawerLayout>


</RelativeLayout>
 public  void filter(String s, ImageView img) {
        HashMap<String, Object> wp = new HashMap<>();

       if (!s.equals("")) {

            fdata.clear();
            for (int i = 0 ;i<data.size();i++) {
                wp = data.get(i);


                if (wp.get("name").toString().toLowerCase().contains(s)) {



                    fdata.add(wp);


                    //notifyDataSetChanged();

                }

            }

        }
        else {
           fdata = new ArrayList<>(selecteddata);
           //notifyDataSetChanged();
       }
        notifyDataSetChanged();
    }