0

smsmanager が機能していない、エラーも表示されていない、機能がまったく機能していない、ダイアログの却下のみが機能している。

メインアクティビティ.java

public class MainActivity extends Activity implements FetchDataListener,OnClickListener { private static final int ACTIVITY_CREATE=0; プライベート ProgressDialog ダイアログ。リストビュー lv; プライベート リスト アイテム。プライベート ボタン btnGetSelected; //プライベート ProjectsDbAdapter mDbHelper; //プライベート SimpleCursorAdapter dataAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_list_item);  
         //mDbHelper = new ProjectsDbAdapter(this);
            //mDbHelper.open();
            //fillData();
            //registerForContextMenu(getListView());

     lv =(ListView)findViewById(R.id.list);
     btnGetSelected = (Button) findViewById(R.id.btnget);
        btnGetSelected.setOnClickListener(this);

        initView();
    }



    private void initView()
    {
        // show progress dialog
        dialog = ProgressDialog.show(this, "", "Loading...");
        String url = "http://dry-brushlands-3645.herokuapp.com/posts.json";
        FetchDataTask task = new FetchDataTask(this);
        task.execute(url);

        //mDbHelper.open();     
        //Cursor projectsCursor = mDbHelper.fetchAllProjects();
        //startManagingCursor(projectsCursor);

        // Create an array to specify the fields we want to display in the list (only TITLE)
        //String[] from = new String[]{ProjectsDbAdapter.KEY_TITLE};

        // and an array of the fields we want to bind those fields to (in this case just text1)
        //int[] to = new int[]{R.id.text1};

        /* Now create a simple cursor adapter and set it to display
        SimpleCursorAdapter projects = 
                new SimpleCursorAdapter(this, R.layout.activity_row, projectsCursor, from, to);
        setListAdapter(projects);
        */
        // create the adapter using the cursor pointing to the desired data 
        //as well as the layout information
         /*dataAdapter  = new SimpleCursorAdapter(
          this, R.layout.activity_row, 
          projectsCursor, 
          from, 
          to,
          0);
         setListAdapter(dataAdapter);
        */
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        //getMenuInflater().inflate(R.menu.activity_main, menu);
        super.onCreateOptionsMenu(menu);
         MenuInflater mi = getMenuInflater();
            mi.inflate(R.menu.activity_main, menu); 
        return true;

    }

     @Override
        public boolean onMenuItemSelected(int featureId, MenuItem item) {

                createProject();

            return super.onMenuItemSelected(featureId, item);
     }

     private void createProject() {
            Intent i = new Intent(this, ProjectEditActivity.class);
            startActivityForResult(i, ACTIVITY_CREATE);   
        }

     @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
            super.onActivityResult(requestCode, resultCode, intent);
            initView();
        }

    @Override
    public void onFetchComplete(List<Application> data)
    {
        this.items = data;
        // dismiss the progress dialog
        if ( dialog != null )
            dialog.dismiss();
        // create new adapter
        ApplicationAdapter adapter = new ApplicationAdapter(this, data);
        // set the adapter to list
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener() {

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

                CheckBox chk = (CheckBox) view.findViewById(R.id.checkbox);
                Application bean = items.get(position);
                if (bean.isSelected()) {
                    bean.setSelected(false);
                    chk.setChecked(false);
                } else {
                    bean.setSelected(true);
                    chk.setChecked(true);
                }

            }
        });
    }

    // Toast is here...
        private void showToast(String msg) {
            Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        }

    @Override
    public void onFetchFailure(String msg)
    {
        // dismiss the progress dialog
        if ( dialog != null )
            dialog.dismiss();
        // show failure message
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }



    @Override
    public void onClick(View v) {
        StringBuffer sb = new StringBuffer();

        // Retrive Data from list
        for (Application bean : items) {

            if (bean.isSelected()) {
                sb.append(Html.fromHtml(bean.getContent()));
                sb.append(",");
            }
        }

        showAlertView(sb.toString().trim());

    }

    @SuppressWarnings("deprecation")
    private void showAlertView(String str) {
        AlertDialog alert = new AlertDialog.Builder(this).create();
        if (TextUtils.isEmpty(str)) {
            alert.setTitle("Not Selected");
            alert.setMessage("No One is Seleceted!!!");
        } else {
            // Remove , end of the name
            String strContactList = str.substring(0, str.length() - 1);

            alert.setTitle("Selected");
            alert.setMessage(strContactList);
        }
        alert.setButton("Ok", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                //sendSMS();
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
                dialog.dismiss();
            }


        });

        In my code i am using sms manager for sending sms which are the thing getting from my listview,it has to send sms,but after clicking the ok button,nothing is work, dialog dismiss only working,not sms manager is not working.
4

1 に答える 1

0
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);

ここの「phoneNo」にはSMSを送りたい番号を指定

電話番号またはメッセージとして送信する必要があるテキストデータを含む選択されたデータは何をしますか。「phoneNo」はあなたが渡している文字列です。電話番号の代わりに phoneNo と入力すると、どの番号にどのように送信されますか。その最初のパラメーターは、SMS を送信する電話番号です。リストから電話番号を選択している場合は、それを変数に取得し、その変数を「phoneNo」の代わりに配置します

アラートが表示されたときに番号を入力する場合は、ここにコードがあります

private void showAlertView(String str) {
    final EditText input = new EditText(YOURACTIVITYNAME.this);
    AlertDialog alert = new AlertDialog.Builder(YOURACTIVITYNAME.this)
    if (TextUtils.isEmpty(str)) {
        alert.setTitle("Not Selected");
        alert.setMessage("No One is Seleceted!!!");
    } else {
        // Remove , end of the name
        String strContactList = str.substring(0, str.length() - 1);

        alert.setTitle("Selected");
        alert.setMessage(strContactList);
    }
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                 String value;

        @Override
        public void onClick(DialogInterface dialog, int which) {
            //sendSMS();

            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(input.getText().toString(), null, "sms message", null, null);
            dialog.dismiss();
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                }
            }).show();
于 2013-06-05T11:47:45.857 に答える