java - 安卓分享按钮

标签 java android arrays string

编辑*:对于hovanessyan

private String getWheelValue(int id) {
    WheelView wheel = getWheel(R.id.passw_1);
    int index = wheel.getCurrentItem();
    ((ArrayWheelAdapter<String>) wheel.getViewAdapter()).getItemText(index).toString();
    final String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);

最佳答案

首先,您的代码将无法编译,因为:

initWheel(R.id.passw_2, new String[] { "Are", "Going", ""Went });
initWheel(R.id.passw_3, new String[] { "There", "Here", ""Away });

您的按钮没有被点击,因为在提供的代码中,您从未调用过 getWheelValue()

您应该在 onCreate() 方法中获取对按钮的引用并附加 onClickListener。

您应该从...开始您的更改

@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); 

        }
    });

    Button share = (Button) findViewById(R.id.btn_share);
    share.setOnClickListener(new OnClickListener() {   
        public void onClick(View v) {
           // call some other methods before that I guess...

           String values = getAllWheelValues();
           startActivity(createEmailIntent(values)); 
    }
    });

}

    private Intent createEmailIntent(String values) { 

           Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
           emailIntent.setType("text/plain");
           emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.Subject));
           emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, values);

           return emailIntent;
    }

编辑:

我认为你应该有类似的东西,并在分享按钮的 onClick() 中调用 getAllWheelValues():

private String getAllWheelValues() {
 String val1 = getWheelValue(R.id.passw_1);
 String val2 = getWheelValue(R.id.passw_2);
 String val3 = getWheelValue(R.id.passw_3);

 return val1+" "+val2+" "+val3;
}

private String getWheelValue(int id) {
    WheelView wheel = getWheel(id);
    int index = wheel.getCurrentItem();
    return ((ArrayWheelAdapter<String>) wheel.getViewAdapter()).getItemText(index).toString();
}

关于java - 安卓分享按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8224909/

相关文章:

java - Comparable<T> 和compareTo

Android 音频模式更改通知

android - 从 listView 中删除标题

c++ - 将结构内的二维数组传递给另一个结构

java - 如何在java中使用for循环显示图像

java - 在Eclipse中运行java程序

java - 在两个类之间建立正确的关系

android - 存储状态数据的更好方式/位置( ListView )

ruby - MongoDB:如何存储大数组? (ERR Document too large: This BSON documents is limited to 16777216 bytes)

java - 为什么当我使用 NetBeans 6.8 和 Eclipse 运行此代码时输出不同?