如何在片段内单击按钮打开快速办公应用程序

时间:2013-12-30 12:25:44

标签: android android-fragments

您好,我是Android开发的新手,我需要知道如何打开快速办公室,点击一个片段里面的按钮我试过谷歌它没有运气:/

这是我的代码

package com.sibext.android_shelf;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;


import com.d4a.tobias.R;

public class Three extends Fragment implements OnClickListener {



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Get the view from fragmenttab2.xml
        View v=inflater.inflate(R.layout.three, container, false);






    return v;



    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }

















}

任何代码示例??

非常感谢任何帮助!

由于

1 个答案:

答案 0 :(得分:1)

以下是将按钮实现为Fragment的方法:

public class Three extends Fragment {

Button btn;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // Get the view from fragmenttab2.xml
    View v=inflater.inflate(R.layout.three, container, false);
    btn=(Button)v.findViewbyid(R.id.button1);


   btn.setonclickListner(new onClicklistner(){
     Intent intent = new Intent();

                           intent.setAction(android.content.Intent.ACTION_VIEW);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                         Uri uri = Uri.fromFile(file);
                         intent.setDataAndType(uri,"application/*");
                            try {

                                startActivity(intent);
                            } catch (Exception e) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(
                                        contxt);
                                builder.setTitle("No Application Found");
                                builder.setMessage("Download application from Android Market?");
                                builder.setPositiveButton(
                                        "Yes, Please",
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(
                                                    DialogInterface dialog,
                                                    int which) {
                                                Intent marketIntent = new Intent(
                                                        Intent.ACTION_VIEW);
                                                marketIntent.setData(Uri
                                                        .parse("market://details?id=com.infraware.polarisoffice4"));

                                                mProgressDialog.dismiss();
                                                startActivity(marketIntent);
                                             }
                                        });
                                builder.setNegativeButton("No, Thanks",
                                        null);
                                builder.create().show();
                            }
    }); 


return v;
 }
}

我告诉你如何实现这一点。这张地图对你有帮助。