Кнопка Android Share - PullRequest
       2

Кнопка Android Share

1 голос
/ 22 ноября 2011

РЕДАКТИРОВАТЬ *: ДЛЯ ОВАНЕСЯН

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

1 Ответ

1 голос
/ 22 ноября 2011

Во-первых, ваш код не будет компилироваться из-за:

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

Ваша кнопка не нажимает, потому что в представленном коде вы никогда не позвоните getWheelValue()

Вам нужно получить ссылкук вашей кнопке и прикрепите onClickListener, в вашем методе onCreate ().

Вы должны начать свои изменения с чего-то вроде ...

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

РЕДАКТИРОВАТЬ:

Я думаюу вас должно быть что-то вроде этого, и позвоните getAllWheelValues() в onClick() кнопку «Поделиться»:

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();
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...