简体   繁体   English

Android共享按钮从应用程序获取价值

[英]Android Share Button Get Value From App

i have a app that has three spinning wheels that display a sentance when the user spins the wheels you can see the code below. 我有一个应用程序,该应用程序具有三个旋转的车轮,当用户旋转车轮时,这些车轮会显示一个表情,您可以看到以下代码。

I am using the kankan wheel project btw http://code.google.com/p/android-wheel/ . 我正在使用kankan wheel项目btw http://code.google.com/p/android-wheel/

My question is, is there a way i can get the 3 words that are displayed (The row in the middle see link above image) into a kind of value string and then share what the value string is - the code is below. 我的问题是,有没有一种方法可以将显示的3个字(中间的行,见图片上方的链接)转换成一种值字符串,然后共享值字符串是什么-下面的代码。 Thanks in advance. 提前致谢。

    public class PasswActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.passw_layout);
    initWheel(R.id.passw_1, new String[] { "You", "Me", "Us" });
    initWheel(R.id.passw_2, new String[] { "Are", "Going", ""Went });
    initWheel(R.id.passw_3, new String[] { "There", "Here", ""Away });



    Button mix = (Button) findViewById(R.id.btn_mix);
    mix.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mixWheel(R.id.passw_1);
            mixWheel(R.id.passw_2);
            mixWheel(R.id.passw_3);

        }
    });

}

// Wheel scrolled flag
private boolean wheelScrolled = false;

// Wheel scrolled listener
OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {
    public void onScrollingStarted(WheelView wheel) {
        wheelScrolled = true;
    }

    public void onScrollingFinished(WheelView wheel) {
        wheelScrolled = false;

    }
};

// Wheel changed listener
private OnWheelChangedListener changedListener = new OnWheelChangedListener() {
    public void onChanged(WheelView wheel, int oldValue, int newValue) {
        if (!wheelScrolled) {

        }
    }
};

/**
 * Initializes wheel
 * 
 * @param id
 *            the wheel widget Id
 */
private void initWheel(int id, String[] values) {
    WheelView wheel = getWheel(id);
    wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, values));
    wheel.setCurrentItem((int) (Math.random() * 10));
    wheel.addChangingListener(changedListener);
    wheel.addScrollingListener(scrolledListener);
    wheel.setCyclic(true);
    wheel.setInterpolator(new AnticipateOvershootInterpolator());

}

/**
 * Returns wheel by Id
 * 
 * @param id
 *            the wheel Id
 * @return the wheel with passed Id
 */
private WheelView getWheel(int id) {
    return (WheelView) findViewById(id);

}



/**
 * Tests entered PIN
 * 
 * @param v1
 * @param v2
 * @param v3
 * @param v4
 * @return true
 */
private boolean testPin(int v1, int v2, int v3, int v4) {
    return testWheelValue(R.id.passw_1, v1)
            && testWheelValue(R.id.passw_2, v2)
            && testWheelValue(R.id.passw_3, v3);

}

/**
 * Tests wheel value
 * 
 * @param id
 *            the wheel Id
 * @param value
 *            the value to test
 * @return true if wheel value is equal to passed value
 */
private boolean testWheelValue(int id, int value) {
    return getWheel(id).getCurrentItem() == value;
}

/**
 * Mixes wheel
 * 
 * @param id
 *            the wheel id
 */
private void mixWheel(int id) {
    WheelView wheel = getWheel(id);
    wheel.scroll(-25 + (int) (Math.random() * 50), 2000);
}
 }
private String getWheelValue(int id) {
    WheelView wheel = getWheel(R.id.passw_1);
    int index = wheel.getCurrentItem();
    ((ArrayWheelAdapter<String>) wheel.getViewAdapter()).getItemText(index).toString();  
}

So you can get your strings by: 因此,您可以通过以下方式获取字符串:

String message = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " getWheelValue(R.id.passw_3)

Send SMS: 发简讯:

    private void sendSMS(String phoneNumber, String message)
    {        
        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MyActivity.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM