我是android编程的新手。我在互联网上搜索,但我找不到任何解决方案,也许因为我没有良好的英语。无论如何。当用户点击网络链接时,我想向用户显示启用wifi的警报对话框,然后用户点击确定按钮,显示wifi设置。
这是我的TextView链接:
<TextView
android:id="@+id/sitename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/site2"
android:background="@color/white"
android:layout_below="@id/address"
android:layout_toLeftOf="@id/site"
android:paddingTop="3dp"
android:paddingRight="5dp"
android:autoLink="web"/>
我用strings.xml设置了web文本。
抱歉,如果我的问题是重复的,抱歉我的英语不好。 欢呼声。
编辑:Contact.java:
public class Contact extends Fragment {
public String fonts="Tahoma.TTF";
Typeface face;
TextView siteName;
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
View view=inflater.inflate(R.layout.contact, container, false);
siteName=(TextView)view.findViewById(R.id.sitename);
siteName.setOnClickListener(onClickListener);
return view;
}
private OnClickListener onClickListener=new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.sitename:
AlertDialog.Builder alertDialog=new AlertDialog.Builder(getActivity());
alertDialog.setTitle("Turn on WI-Fi..");
alertDialog.setMessage("Do you want to go to wifi settings?");
alertDialog.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
}
});
alertDialog.show();
break;
}
}
};
}
答案 0 :(得分:2)
点击按钮尝试此操作:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(
this);
// Setting Dialog Title
alertDialog.setTitle("Confirm...");
// Setting Dialog Message
alertDialog.setMessage("Do you want to go to wifi settings?");
// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.ic_launcher);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Activity transfer to wifi settings
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("no",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
答案 1 :(得分:0)
尝试将以下内容添加到onClick
Button
context.startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
这会将用户直接重定向到wifi设置屏幕
希望这有效
答案 2 :(得分:0)
这应该有效
startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));