如何将字符串从一个活动传递到另一个活动,并用于拨号盘和电子邮件目的

尼泊尔人

我有两个适配器和另一个活动。适配器将Firebase数据结构中每个位置的额外字符串发送到下一个活动中,在该活动中显示从适配器传递来的数据。效果很好。我无法在Textview中显示数据。但是,当我打算拨打电话或发送电子邮件时,则无法使用我要使用的Extras,但是当我在Textview中设置setText时,它们显示了准确的数据。请帮助

这是适配器中的方法

@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {

        database = FirebaseDatabase.getInstance();
        dbreference = database.getReference("gender");

        g = bookslist.get(position);
 holder.teacher_quali.setText(g.getBqualifications());

        holder.profile_details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(v.getContext(), gender_details.class);

                intent.putExtra(NEAR_LOCATION, g.getBlocation());
                intent.putExtra(AVAILAIBILITY, g.getBavailaile());

                intent.putExtra(MOBILE, g.getSellermobile());
                intent.putExtra(EMAIL, g.getSelleremail());


                v.getContext().startActivity(intent);
            }
});

我将MOBILE和EMAIL定义为

public static final String MOBILE = "other_mobile";
public static final String EMAIL= "other_email";

在同一适配器视图中,我的活动是

public class gender_details extends AppCompatActivity {

    private TextView tutor_email,tutor_mobile;
    private ImageView img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile_details);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_details); // get the reference of Toolbar
        toolbar.setTitle(getIntent().getStringExtra(KEY_NAME));
        toolbar.setLogo(R.drawable.ic_person_black_24dp);
        setSupportActionBar(toolbar);




        String tutor_email_txt = "";
        String tutor_mobile_txt = "";


        tutor_email_txt = intent.getStringExtra(EMAIL);
        tutor_mobile_txt = intent.getStringExtra(MOBILE);
        // Setting values

        TextView Email_Txt = (TextView) findViewById(R.id.tutor_email);
        Email_Txt.setText(tutor_email_txt);

         TextView Contact_Txt = (TextView) findViewById(R.id.tutor_contact);
        Contact_Txt.setText(String tutor_mobile_txt);
    }
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.toolbar_menu, menu);
            return true;
        }
// Activity's overrided method used to perform click events on menu items
        @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();
//noinspection SimplifiableIfStatement
// Display menu item's title by using a Toast.
            if (id == R.id.action_call) {


                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:"+tutor_mobile_txt));
                startActivity(intent);


                return true;
            } else if (id == R.id.action_email) {

                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("plain/text");
                intent.putExtra(Intent.EXTRA_EMAIL, tutor_email_txt);
                intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
                intent.putExtra(Intent.EXTRA_TEXT, "mail body");
                startActivity(Intent.createChooser(intent, ""));

                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    @Override
    public void onBackPressed() {
        Intent intent = new Intent(gender_details.this, MainActivity.class);
        startActivity(intent);
    }
}

正如您在Textview中看到的那样,信息可以正确显示,但是当我习惯使用Intent Action Dail或发送电子邮件时...我无法这样做。

请帮忙

法兹·米尔

试试这个:

全局声明变量

public class gender_details extends AppCompatActivity {

    private TextView tutor_email,tutor_mobile;
    private ImageView img;
     String tutor_email_txt;
        String tutor_mobile_txt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile_details);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_details); // get the reference of Toolbar
        toolbar.setTitle(getIntent().getStringExtra(KEY_NAME));
        toolbar.setLogo(R.drawable.ic_person_black_24dp);
        setSupportActionBar(toolbar);




       


        tutor_email_txt = intent.getStringExtra(EMAIL);
        tutor_mobilee_txt = intent.getStringExtra(MOBILE);
        // Setting values

        TextView Email_Txt = (TextView) findViewById(R.id.tutor_email);
        Email_Txt.setText(tutor_email_txt);

         TextView Contact_Txt = (TextView) findViewById(R.id.tutor_contact);
        Contact_Txt.setText(String tutor_mobile_txt);
    }
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.toolbar_menu, menu);
            return true;
        }
// Activity's overrided method used to perform click events on menu items
        @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();
//noinspection SimplifiableIfStatement
// Display menu item's title by using a Toast.
            if (id == R.id.action_call) {


                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:"+tutor_mobile_txt));
                startActivity(intent);


                return true;
            } else if (id == R.id.action_email) {

                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("plain/text");
                intent.putExtra(Intent.EXTRA_EMAIL, tutor_email_txt);
                intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
                intent.putExtra(Intent.EXTRA_TEXT, "mail body");
                startActivity(Intent.createChooser(intent, ""));

                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    @Override
    public void onBackPressed() {
        Intent intent = new Intent(gender_details.this, MainActivity.class);
        startActivity(intent);
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将编辑文本字符串从一个活动传递到另一个活动中的方法?

如何将 JsonArray 从一个活动传递到另一个活动

如何将位图对象从一个活动传递到另一个活动

如何将变量从一个活动传递到另一个活动?

如何将JWT令牌从一个活动传递到另一个活动?

如何将视频链接从一个活动传递到另一个活动?

如何将数据从一个活动传递到另一个列表视图活动?

将字符串的ArrayList从一个活动传递到另一个活动时,为什么会出现空指针异常?

Storm:如何将字符串数组从一个螺栓传递到另一个?

如何在Android中将两个字符串从一个活动传递到另一个活动

如何将数据从一个活动传递到另一活动

将GoogleApiClient obj从一个活动传递到另一个活动

将QBRTCSession对象从一个活动传递到另一个活动

将布局从一个活动传递到另一个活动

如何显示从一个活动传递到另一个活动的值?

如何将不可包裹的物体从一个活动传递到另一个活动?

将二维字符串数组变量从1个活动传递到另一个活动

如何将ArrayList中的类从一个活动传递给另一个活动

如何将文本从一个活动显示到另一个活动?

Android || 如何将图像从一个活动解析到另一个活动?

如何将数据从一个活动解析到另一个活动

如何将字符串从AsyncTask返回到另一个活动

如何将数据从主要活动传递到另一个活动

如何将价值从不同的活动传递到另一个活动

如何将值从活动传递到Kotlin中的另一个活动

如何将数据从每个活动传递到另一个活动?

如何将 int 值从一个活动传递到另一个活动并在 TextView 中显示?

如何将图像从一个活动动态传递到另一个活动,并通过JSON在imageview中显示

如何将字符串变量从一个函数传递给另一个函数?