我正在做一个Android应用程序,当我点击“旅行和假期”按钮时,我想在一个单独的屏幕上显示旅行联系人号码列表。以下是代码:
AppActivity.java
package com.example.android;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class AppActivity extends Activity {
Button button;
Context context = this;
private final CharSequence[] TRAVELS ={"Nirmala travels","RR Tours and Travels","Surabhii Travels"};
String numbertodial;
String phonenumberNT ="08242497051";
String phonenumberRR ="08244280999";
String phonenumberST ="08242212111";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Dialog dialog = null;
AlertDialog.Builder builder = null;
builder = new AlertDialog.Builder(context);
String travels = getString(R.string.app_name);
builder.setTitle(travels);
builder.setSingleChoiceItems(TRAVELS, 3,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
CharSequence s = (TRAVELS[item]);
if (s.equals("Nirmala travels")){numbertodial =phonenumberNT; }
if (s.equals("RR Tours and Travels")){numbertodial=phonenumberRR; }
if (s.equals("Surabhii Travels")){numbertodial=phonenumberST ;}
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:"+numbertodial ));
startActivity(callIntent);
dialog.dismiss();
}});
dialog = builder.create();
dialog.show();
return;
}
});
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Travels and Holidays" />
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Travels and Holidays Details</string>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".AppActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
当点击“旅行和假期”按钮时,它会在同一个屏幕上显示这3趟旅行的名字。当选择任意1时,它直接调用该数字。
但我想要的是:当我点击第一个屏幕上的“旅行和假期”按钮时,我希望在另一个屏幕上显示旅行姓名和联系方式。当点击任何旅行,它应该重定向到该号码的看涨选项。
我哪里出问题了?请帮帮忙。提前感谢
发布于 2015-05-19 05:21:39
你必须创造另一个活动,然后你重定向到那个地方,把你的不和名字写在那里。
Intent i=new Intent(yourcontext,yourActivity.class);
i.putExtra("no","yourno");
i.putExtra("name","yourname");
startActivity(i);
然后开始你的活动
String no=getIntent().getStringExtra("no");
String name=getIntent().getStringExtra("no");
要获得更多信息,您可以看到这个链接
发布于 2015-05-19 05:21:26
创建一个单独的活动/片段来显示“旅行和假日”详细信息。在"Travels “按钮上调用此活动/片段,然后单击"Travels ”详细信息值,使用意图putExtra()将其传递给details活动/片段。如果创建活动,请确保在AndroidManifest.xml中声明活动。
https://stackoverflow.com/questions/30317264
复制相似问题