OnItemClickListener в Custom ListView Adapter возвращает неверные данные - PullRequest
0 голосов
/ 07 апреля 2019

У меня есть Custom Listview с панелью поиска, которая отлично работает.Теперь я создал OnItemClickListener таким образом, чтобы при щелчке по возвращенному элементу поиска в представлении списка открывалось новое действие, в котором выбранные элементы отображались в новом действии.Однако значение, возвращаемое при нажатии на ListView, неверно, и я занимаюсь этим уже более 3 дней и, похоже, не могу найти проблему даже при проверке примеров.Ниже мой код.Буду признателен за любую помощь в правильном направлении

это мой setOnItemClickListener в моей MainActivity

 mListViewTakeAwayPacks.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {

                    String takeAwayPack = adapterView.getItemAtPosition(position).toString();


                    Toast.makeText(ListTakeAwayPackActivity.this, "Selected: " + takeAwayPack, Toast.LENGTH_SHORT).show();

                    Cursor takeAwayPackData = controller.getTakeAwayPAckID(takeAwayPack);  //get the ID associatd with the name




                    while (takeAwayPackData.moveToNext()){

                     }
                        Intent editTakeAwayPackIntent = new Intent(ListTakeAwayPackActivity.this, EditTakeAwayPackActivity.class);
                        editTakeAwayPackIntent.putExtra("PackType", takeAwayPack);
                        startActivity(editTakeAwayPackIntent);

                }
            });

это мой пользовательский адаптер

public class TwoColumn_ListAdaper extends BaseAdapter implements Filterable {
   private ArrayList<User3> mOriginalValues; // Original Values
    private ArrayList<User3> mDisplayedValues;    // Values to be displayed
    LayoutInflater inflater;
   public TwoColumn_ListAdaper(Context context, int list_take_away_pack_adapter_view, ArrayList<User3> mProductArrayList){
       this.mOriginalValues = mProductArrayList;
        this.mDisplayedValues = mProductArrayList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDisplayedValues.size();
    }
    @Override
    public Object getItem(int position) {
        return mDisplayedValues.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    private class ViewHolder {   // holds the views from the list_take_away_pack_ada[ter_view.xml, from the Textview and the parent Linear layout
        LinearLayout llContainer;
        TextView takeawaypacktype,takeawaypackprice;
    }
    public View getView(int position, View convertView, ViewGroup parents){
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_take_away_pack_adapter_view, null);
            holder.llContainer = (LinearLayout)convertView.findViewById(R.id.llContainer);
            holder.takeawaypacktype = (TextView) convertView.findViewById(R.id.takeawaypacktype);
            holder.takeawaypackprice = (TextView) convertView.findViewById(R.id.takeawaypackprice);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }      holder.takeawaypacktype.setText(mDisplayedValues.get(position).getmTakeAwayPackType());      holder.takeawaypackprice.setText(mDisplayedValues.get(position).getmTakeAwayPackCost()+"");
        holder.llContainer.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            }
        });
        convertView.setClickable(false);    //add a single line of code like this: convertView.setClickable(false) because the OnItemCLickListener not working in listview.    found here /6313056/onitemclicklistener-ne-rabotaet-v-prosmotre-spiska
        return convertView;
    }

Это файл журнала

2019-04-08 13:02:43.068 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@47d85e8 time:409548988
2019-04-08 13:02:45.921 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/ViewRootImpl: ViewPostImeInputStage processPointer 0
2019-04-08 13:02:46.071 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/ViewRootImpl: ViewPostImeInputStage processPointer 1
2019-04-08 13:02:46.081 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/TextView: setTypeface with style : 0
2019-04-08 13:02:46.081 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement I/Timeline: Timeline: Activity_launch_request id:com.example.noruw.foodoclockbusinessprocessmanagement time:409552007
2019-04-08 13:02:46.101 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/ViewRootImpl: #1 mView = android.widget.LinearLayout{98564ec V.E...... ......I. 0,0-0,0}
2019-04-08 13:02:46.171 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
2019-04-08 13:02:46.201 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/TextView: setTypeface with style : 0
2019-04-08 13:02:46.201 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/TextView: setTypeface with style : 0
2019-04-08 13:02:46.211 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/TextView: setTypeface with style : 0
2019-04-08 13:02:46.211 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/TextView: setTypeface with style : 0
2019-04-08 13:02:46.221 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/TextView: setTypeface with style : 0
2019-04-08 13:02:46.221 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/TextView: setTypeface with style : 0
2019-04-08 13:02:46.231 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/SecWifiDisplayUtil: Metadata value : SecSettings2
2019-04-08 13:02:46.231 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{b02ba23 I.E...... R.....ID 0,0-0,0}
2019-04-08 13:02:46.301 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 36 - 0, 0) vi=Rect(0, 36 - 0, 0) or=1
2019-04-08 13:02:46.361 27225-27286/com.example.noruw.foodoclockbusinessprocessmanagement D/OpenGLRenderer: endAllStagingAnimators on 0xa122f180 (ListView) with handle 0x9e18b930
2019-04-08 13:02:46.371 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2b43752 time:409552294
2019-04-08 13:02:46.581 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement V/ActivityThread: updateVisibility : ActivityRecord{5a8d6c0 token=android.os.BinderProxy@47d85e8 {com.example.noruw.foodoclockbusinessprocessmanagement/com.example.noruw.foodoclockbusinessprocessmanagement.Take_Away_Pack_Management.ListTakeAwayPackActivity}} show : false
2019-04-08 13:02:48.093 27225-27225/com.example.noruw.foodoclockbusinessprocessmanagement D/ViewRootImpl: #3 mView = null
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...