0

私はAndroidを学び始めています。問題があります。コンテンツがarrayListのautocompleteTextViewがあります。次に、autoCompleteTextView をクリックしたときに、arraylist 内の要素の位置を取得したいと考えています。見せてもらえますか?

どうもありがとう !

このコード!

/* ================= looping through All categories ==================== */
        for(int i=0;i<product.length();i++){
            JSONObject c = product.getJSONObject(i);
            // Storing each json item in variable
            pro_id = c.getString(TAG_ID);
            pro_name = c.getString(TAG_NAME);

            name_product.add(pro_name);
        } // end for products
    } catch (JSONException e) {
        e.printStackTrace();
    }   

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, name_product);
    AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.result_search);

    textView.setThreshold(1);
    textView.setAdapter(adapter);
    textView.setOnItemClickListener(new OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {

          //here position is your selected item id

          /*String selecteditem =name_product.get(position);
            Log.d("Test",selecteditem.toString());
            int pos = Integer.parseInt(selecteditem);
            Toast.makeText(getApplicationContext(), "cvxcvcv",pos).show();*/

            // I want to get position when i click element in autocompletetextView
        }
    });
4

1 に答える 1

1

試す

    autocompletetextview.setOnItemClickListener(new OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {

              //here position is your selected item id

              int selectedposition=position;


            }
        });
于 2013-05-17T13:14:42.343 に答える