我是android编程的新手。我在互联网上搜索但我找不到任何解决方案,也许为此我的英语不好。反正。当用户单击网络链接时,我想向打开 wifi 的用户显示警报对话框,然后用户单击 OK 按钮,显示 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;
}
}
};
}