0

Good day everyone.

Unfortunately i don't have much experience with java and i run into a probably very basic issue. I am filling a list view and when i click one of the list items i want to send a string to another intent. but the value of the string is always the same even tough it show up correctly in the list view. I guess it has to do with the String getting overwritten every time a new item appears.

I want parts[3] to be send to another function in the onItemClick how would i accomplish that?

Here is the code

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try {
            ViewHolder holder;
            final String uuidbeacon;
            final String pid;
            uuidbeacon = arrayL.get(position).getProximityUuid().toString();
            minorbeacon = arrayL.get(position).getMinor();
            rangebeacon = arrayL.get(position).getAccuracy();
            parts = fetchTums(uuidbeacon).split("::");

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

                if(parts[0].equals("1")) {
                    holder = new ViewHolder(convertView = inflater.inflate(R.layout.tupple_monitoring, null));
                    holder.beacon_image.setImageDrawable(getTumImage("http://127.0.0.1/uploads/face/" + parts[4]));
                    holder.beacon_uuid.setText(parts[1]);
                    holder.beacon_txpower.setText(parts[3]);

                    if(parts[2].equals("1"))
                    {
                        holder.beacon_row.setBackgroundColor(Color.parseColor("#B6B6B6"));
                        holder.image_lock.setVisibility(View.VISIBLE);
                    }
                }
                if(parts[0].equals("0"))
                {
                    holder = new ViewHolder(convertView = inflater.inflate(R.layout.tupple_monitoringe, null));

                }
            }
            pid = parts[3];
            if (arrayL.get(position).getProximityUuid() != null)



            list.setOnItemClickListener(new AdapterView.OnItemClickListener()
            {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id )
                {
                    //list.setItemChecked(position, true);
                    //view.setBackgroundColor(Color.BLUE);
                    toastThis(pid);
                   if(parts[2].equals("1")){

                       pin(pid);
                   }
                   else{
                        if(pid != null){
                            openPage(parts[3], "", parts[1]);
                        }
                   }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }


        return convertView;
    }
Maantje
  • 1,781
  • 2
  • 20
  • 33

2 Answers2

0

I would try to implement the click listener outside of your adapter. For instance, inside a Fragment.

Something like this:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    YourAdapter adapter = new YourAdapter(getActivity(), mItems);
    ListView list       = (ListView) view.findViewById(R.id.your_list_id);

    list.setAdapter(adapter);
    list.setOnItemClickListener(onItemClicked());
}


private AdapterView.OnItemClickListener onItemClicked() {
    return new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int i, long l) {
            YourItem item = (YourItem) parent.getItemAtPosition(i);
            // your magic happens here
        }
    };
}
Julio Betta
  • 2,275
  • 1
  • 25
  • 25
0

You have to pick the value using the position received from onItemClick to get exact item clicked. In your case you will have to get the value at index (position) in your arrayL like below.

String item = arrayL[position];

Jibran Khan
  • 3,236
  • 4
  • 37
  • 50