在按钮后向sendEvent添加文本和微调器选项

时间:2015-01-05 14:17:51

标签: android

下面是我的第一个项目的完整java代码,我希望能够输入文本并从微调器中选择一个选项并将它们作为事件发送。

Please take a look below at my comment (--> ) I don't know how to do it

**package com.app.app;
import java.util.Map;
import com.appsf.appsfLib;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Menu;
import android.content.Intent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import java.text.DecimalFormat;
import android.widget.EditText;
import android.widget.Spinner;
          public class MainActivity extends Activity implements OnClickListener{ 
          Button buttonreg,buttonpur,buttonemail;


        public Spinner Currency;



        @Override
        public void onCreate(Bundle savedInstanceState) {
        appsfLib.setappsfKey("JuZ");
        appsfLib.sendTracking(getApplicationContext());
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Currency = (Spinner)findViewById(R.id.spinner1);
        final EditText textEntercurrency = (EditText)findViewById(R.id.textEntercurrency);





        buttonreg = (Button) findViewById(R.id.buttonreg);
        buttonpur = (Button) findViewById(R.id.buttonpur);
        buttonemail =(Button) findViewById(R.id.buttonemail);
        buttonreg.setOnClickListener(this);
        buttonpur.setOnClickListener(this);
        buttonemail.setOnClickListener(this);
        sendEvent(getApplicationContext(),"Loyal_Users","");


        @Override
        public void onClick(View v) {
         switch (v.getId()) {
         case R.id.buttonreg:
         sendEvent(getApplicationContext(),"registration",""); 
         break;
         case R.id.buttonpur:
         appsfLib.setCurrencyCode("");   **--> I want to insert in the "" an spinner options  that will be chosen from the spinner ( 5 options) called "spinner1"**
    enter code here
         sendEvent(getApplicationContext(),"purchase","");   **--> I want to insert in the "" an amount of purchase that will be entered from my text field called "textEntercurrency"**
          break;
        case R.id.buttonemail:
          Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
             emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"a@a.com"});
             emailIntent.putExtra(Intent.EXTRA_SUBJECT, " Test");
             emailIntent.setType("plain/text");
             startActivity(Intent.createChooser(emailIntent, "Choose email Client..."));
             break;

        }    

             }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

          };**

希望你能帮我解决这个问题,这是我的第一个项目!谢谢:))

1 个答案:

答案 0 :(得分:0)

  

我想插入""将选择的微调器选项   来自微调器

使用Currency.getSelectedItem()从按钮上的Spinner获取当前所选项目:

appsfLib.setCurrencyCode(Currency.getSelectedItem().toString());
  

我想插入""将输入的购买金额   来自我的文本字段" textEntercurrency"

使用textEntercurrency.getText()从Editext获取文字:

sendEvent(getApplicationContext(),"purchase",
                                  textEntercurrency.getText().toString());