0

私のアプリケーションは一度に 1 人しか見つけることができませんが、アプリで一度に複数の人を見つけたい場合はどうすればよいでしょうか.. for ループを使用してこれを実行しようとしましたが、機能しません.. Add という名前のボタン、編集テキストに任意の番号を書き込んで Add をクリックすると、番号がリストに追加され、 Locate という名前のボタンがあり、その検索ボタンをクリックして、追加された人をアプリに見つけてもらいたい某リストに載っています。誰でもこれを行う方法を教えてもらえますか? これが私のコードです

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fl_number_provider);
    // Show the Up button in the action bar.
    setupActionBar();

    contacts = new ArrayList<String>();
    btnAdd = (Button)findViewById(R.id.btnflAddNum);
    btnAdd.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
        number = (EditText)findViewById(R.id.flPhoneNumber);
        strNumber = number.getText().toString();

        if (strNumber == "")
        {
            Toast.makeText(getApplicationContext(), "Required Field is empty", Toast.LENGTH_LONG).show();

        }else{
        contacts.add(strNumber);
        //x++;
        listview = (ListView) findViewById(R.id.listView1);
        listview.setAdapter(new BaseAdapter() {

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
                View view = inflater.inflate(R.layout.list_row, null);
                TextView textView = (TextView) view.findViewById(R.id.TextView01);
                textView.setText(contacts.get(position));

                return view;
            }

            @Override
            public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
            }

            @Override
            public Object getItem(int position) {
                // TODO Auto-generated method stub
                return contacts.get(position);
            }

            @Override
            public int getCount() {
                // TODO Auto-generated method stub

                return contacts.size();
            }
        });


            number.setText("");
            }

        }
        });



    //number = (EditText) this.findViewById(R.id.flPhoneNumber);
    //listview = (ListView)findViewById(R.id.listView1);
    LocationHead = (TextView) this.findViewById(R.id.flLastKnownLocationHead);
    LastLocation = (TextView) this.findViewById(R.id.flLastLocation);
    getLocation = (Button) this.findViewById(R.id.btnflgetLocation);

    getLocation.setOnClickListener(new View.OnClickListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View arg0) {
            //String num = number.getText().toString();
            //int x = contacts.size();
            try{
            if(contacts == null)
            {

                Toast.makeText(getApplicationContext(), "0", Toast.LENGTH_SHORT).show();
            }
            else{

            //  Toast.makeText(getApplicationContext(), x+" - check", Toast.LENGTH_SHORT).show();

            for(int i = 0; i <= contacts.size(); i++)
            {
            //String x = contacts.get(i).toString();
                    sendMsg(contacts.get(i), contacts.size()+ "message family location");

            //LocationHead.setText(contacts.get(i).toString());
            //LastLocation.setText("waiting....");
            }
            }
            }catch(Exception e){

                Toast.makeText(getApplicationContext(), e.toString()+ "Field Empty", Toast.LENGTH_SHORT).show();
            }
        }
    });
4

2 に答える 2

0

使用する:

if (contacts.size > 0)
  for(int i = 0; i < contacts.size(); i++) {
     ...
于 2013-11-05T18:01:49.693 に答える