Android 分享按钮最后的调整

发布于 2024-12-17 18:05:24 字数 5319 浏览 0 评论 0原文

大家好,我有一个按钮,我试图让用户分享由我应用程序中的三个轮子创建的特定句子,这是我到目前为止的代码:

 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();
        String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
        return values;

        Button share = (Button) findViewById(R.id.tweet);
        share.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                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, getResources().getString(R.string.Message));
                startActivity(emailIntent);

            }
        });

问题出在“wheel.scroll(-25 + (int) (Math.random() * 50), 2000);"

我收到此错误“语法错误,插入“}”以完成 MethodBody”

如果我将其放在该行代码之后,则会出现错误 “按钮共享 = (按钮) findViewById(R.id.tweet);”

说法:无法访问的代码 使用 qcik 修复“删除”,但这只会删除该行代码之后的所有内容,我已在下面发布了完整的代码,以防万一。提前致谢。

    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();
        String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
        return values;

        Button share = (Button) findViewById(R.id.tweet);
        share.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                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, getResources().getString(R.string.Message));
                startActivity(emailIntent);

            }
        });


 }
 }

Hello all i have a button i am trying to let users share a specific sentance that has been created by three wheels that i have in my app this is the code i have so far:

 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();
        String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
        return values;

        Button share = (Button) findViewById(R.id.tweet);
        share.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                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, getResources().getString(R.string.Message));
                startActivity(emailIntent);

            }
        });

The problem is after "wheel.scroll(-25 + (int) (Math.random() * 50), 2000);"

I get this error "Syntax error, insert "}" to complete MethodBody"

If i put it after that line of code i then get an error under
"Button share = (Button) findViewById(R.id.tweet);"

Saying: Unreachable code
With qucik fix "Remove" but this just removes everything after that line of code i have posted the full code below just incase. 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();
        String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
        return values;

        Button share = (Button) findViewById(R.id.tweet);
        share.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                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, getResources().getString(R.string.Message));
                startActivity(emailIntent);

            }
        });


 }
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2024-12-24 18:05:24

为什么你的 getWheelValue() 方法在 mixWheel 内部?尝试像这样将其移到 mixWheel 之外,然后重新组织您的调用,

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();
        String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
        return values;

        Button share = (Button) findViewById(R.id.tweet);
        share.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            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, getResources().getString(R.string.Message));
            startActivity(emailIntent);

        }
    });

}

我什至不确定这是否是有效的语法(方法中的方法) - 如果我错了,有人会纠正我。

Why is your getWheelValue() method inside of mixWheel? Try moving it outside of mixWheel like so, and re-organize your calls

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();
        String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
        return values;

        Button share = (Button) findViewById(R.id.tweet);
        share.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            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, getResources().getString(R.string.Message));
            startActivity(emailIntent);

        }
    });

}

I'm not even sure if that is valid syntax (a method within a method) - someone correct me if I am wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文