EDIT :::请参考下面的答案…

题:::

我非常新的在Android中使用片段,我完全搞砸了.

我只是试图构建一个使用Fragments的简单示例应用程序.我的场景是,我的主要活动有两个片段.第一个片段有一个edittext和一个按钮.第二个片段有一个textview.当我在edittext中输入名称并单击按钮时,第二个片段中的textview应显示在第一个片段的edittext中输入的名称.

我使用静态分配的片段(在XML中分配片段).

请参考下面的XML文件和代码…

activity_main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/fragment_content_1"
        android:name="com.example.fragmentexample.fragment_fragment_1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </fragment>

    <fragment
        android:id="@+id/fragment_content_2"
        android:name="com.example.fragmentexample.fragment_fragment_2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <!-- Preview: layout=@layout/fragment_basic -->
    </fragment>

</LinearLayout>

fragment_fragment_1.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/edtxtPersonName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btnSayHi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Say Hi" />

</LinearLayout>

fragment_fragment_2.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/txtViewResult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I will say Hi" />

</LinearLayout>

Java文件:::

MainActivity.Java

package com.example.fragmentexample;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

    public class MainActivity extends Activity {

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

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.activity_main,menu);
            return true;
        }

    }

Fragment_1.Java

package com.example.fragmentexample;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Fragment_1 extends Fragment{

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
        // Todo Auto-generated method stub      

        View view = inflater.inflate(R.layout.fragment_fragment_1,container,false);

        final EditText edtxtPersonName_Fragment = (EditText) view.findViewById(R.id.edtxtPersonName);
        Button btnSayHi_Fragment = (Button) view.findViewById(R.id.btnSayHi);

        btnSayHi_Fragment.setonClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // Todo Auto-generated method stub

                String name = edtxtPersonName_Fragment.getText().toString();

                FragmentManager fm = getFragmentManager();
                Fragment_2 f2 = (Fragment_2) fm.findFragmentById(R.id.fragment_content_2);

                if(f2 != null && f2.isInLayout())
                {
                    f2.setName(name);
                }

                Activity activity = getActivity();

                if(activity != null)
                {
                    Toast.makeText(activity,"Say&ing Hi in Progress...",Toast.LENGTH_LONG).show();
                }
            }
        });

        return view;


    }

}

Fragment_2.Java

package com.example.fragmentexample;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Fragment_2 extends Fragment{

    View view;

    @Override
    public View onCreateView(LayoutInflater inflater,Bundle savedInstanceState) {
        // Todo Auto-generated method stub

        view = inflater.inflate(R.layout.fragment_fragment_2,false);        
        return view;
    }

    public void setName(String name)
    {
        TextView txtName = (TextView) view.findViewById(R.id.txtViewResult);
        txtName.setText("Hi " + name);
    }

}

当我运行应用程序时,有很多异常.这里是logcat跟踪..

04-16 15:06:48.781: E/AndroidRuntime(420): FATAL EXCEPTION: main
04-16 15:06:48.781: E/AndroidRuntime(420): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragmentexample/com.example.fragmentexample.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:1815)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.ActivityThread.access$500(ActivityThread.java:122)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.os.Looper.loop(Looper.java:132)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.ActivityThread.main(ActivityThread.java:4123)
04-16 15:06:48.781: E/AndroidRuntime(420):  at java.lang.reflect.Method.invokeNative(Native Method)
04-16 15:06:48.781: E/AndroidRuntime(420):  at java.lang.reflect.Method.invoke(Method.java:491)
04-16 15:06:48.781: E/AndroidRuntime(420):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-16 15:06:48.781: E/AndroidRuntime(420):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-16 15:06:48.781: E/AndroidRuntime(420):  at dalvik.system.NativeStart.main(Native Method)
04-16 15:06:48.781: E/AndroidRuntime(420): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
04-16 15:06:48.781: E/AndroidRuntime(420):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:223)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.Activity.setContentView(Activity.java:1786)
04-16 15:06:48.781: E/AndroidRuntime(420):  at com.example.fragmentexample.MainActivity.onCreate(MainActivity.java:12)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.Activity.performCreate(Activity.java:4397)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:1779)
04-16 15:06:48.781: E/AndroidRuntime(420):  ... 11 more
04-16 15:06:48.781: E/AndroidRuntime(420): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.fragmentexample.fragment_fragment_1: make sure class name exists,is public,and has an empty constructor that is public
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.Fragment.instantiate(Fragment.java:567)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.Fragment.instantiate(Fragment.java:535)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.Activity.onCreateView(Activity.java:4168)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:664)
04-16 15:06:48.781: E/AndroidRuntime(420):  ... 21 more
04-16 15:06:48.781: E/AndroidRuntime(420): Caused by: java.lang.classNotFoundException: com.example.fragmentexample.fragment_fragment_1 in loader dalvik.system.PathClassLoader[/data/app/com.example.fragmentexample-1.apk]
04-16 15:06:48.781: E/AndroidRuntime(420):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
04-16 15:06:48.781: E/AndroidRuntime(420):  at java.lang.classLoader.loadClass(ClassLoader.java:540)
04-16 15:06:48.781: E/AndroidRuntime(420):  at java.lang.classLoader.loadClass(ClassLoader.java:500)
04-16 15:06:48.781: E/AndroidRuntime(420):  at android.app.Fragment.instantiate(Fragment.java:557)
04-16 15:06:48.781: E/AndroidRuntime(420):  ... 24 more

我已经看到了如何做到的例子,但无法想像.请指出我做错了的地区,还请张贴正确的方法.

非常感谢你的时间…

EDIT :::

我更改了MainActivity.java以扩展FragmentActivity而不是Activity,并且还将activity_main.xml中的android:name值更改为指向Java Files而不是fragment …

我得到以下例外:::

04-16 15:29:43.821: E/AndroidRuntime(563): FATAL EXCEPTION: main
04-16 15:29:43.821: E/AndroidRuntime(563): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragmentexample/com.example.fragmentexample.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:1815)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.ActivityThread.access$500(ActivityThread.java:122)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.os.Looper.loop(Looper.java:132)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.ActivityThread.main(ActivityThread.java:4123)
04-16 15:29:43.821: E/AndroidRuntime(563):  at java.lang.reflect.Method.invokeNative(Native Method)
04-16 15:29:43.821: E/AndroidRuntime(563):  at java.lang.reflect.Method.invoke(Method.java:491)
04-16 15:29:43.821: E/AndroidRuntime(563):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
04-16 15:29:43.821: E/AndroidRuntime(563):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
04-16 15:29:43.821: E/AndroidRuntime(563):  at dalvik.system.NativeStart.main(Native Method)
04-16 15:29:43.821: E/AndroidRuntime(563): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
04-16 15:29:43.821: E/AndroidRuntime(563):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:223)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.Activity.setContentView(Activity.java:1786)
04-16 15:29:43.821: E/AndroidRuntime(563):  at com.example.fragmentexample.MainActivity.onCreate(MainActivity.java:13)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.Activity.performCreate(Activity.java:4397)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:1779)
04-16 15:29:43.821: E/AndroidRuntime(563):  ... 11 more
04-16 15:29:43.821: E/AndroidRuntime(563): Caused by: java.lang.classCastException: com.example.fragmentexample.Fragment_1 cannot be cast to android.support.v4.app.Fragment
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
04-16 15:29:43.821: E/AndroidRuntime(563):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:660)
04-16 15:29:43.821: E/AndroidRuntime(563):  ... 21 more

以下是activity_main.xml更改的XML文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/fragment_content_1"
        android:name="com.example.fragmentexample.Fragment_1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </fragment>

    <fragment
        android:id="@+id/fragment_content_2"
        android:name="com.example.fragmentexample.Fragment_2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <!-- Preview: layout=@layout/fragment_basic -->
    </fragment>

</LinearLayout>

解决方法

Okie …终于找到了一个解决方案.也许这不是很大的变化.

查看下面的代码…

activity_main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/fragment_content_1"
        android:name="com.example.fragmentexample.Fragment_1"
        android:layout_width="0dip"
        android:layout_weight="0.50"
        android:layout_height="fill_parent" >
    </fragment>

    <fragment
        android:id="@+id/fragment_content_2"
        android:name="com.example.fragmentexample.Fragment_2"
        android:layout_width="0dip"
        android:layout_weight="0.50"
        android:layout_height="fill_parent" >

        <!-- Preview: layout=@layout/fragment_basic -->
    </fragment>

</LinearLayout>

fragment_fragment_1和fragment_fragment_2的布局保持不变.

Fragment_1.Java

package com.example.fragmentexample;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Fragment_1 extends Fragment{

        @Override
        public View onCreateView(LayoutInflater inflater,Bundle savedInstanceState) {
            // Todo Auto-generated method stub      

            View view = inflater.inflate(R.layout.fragment_fragment_1,false);

            final EditText edtxtPersonName_Fragment = (EditText) view.findViewById(R.id.edtxtPersonName);
            Button btnSayHi_Fragment = (Button) view.findViewById(R.id.btnSayHi);

            btnSayHi_Fragment.setonClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // Todo Auto-generated method stub

                    String name = edtxtPersonName_Fragment.getText().toString();

                    FragmentManager fm = getFragmentManager();
                    Fragment_2 f2 = (Fragment_2) fm.findFragmentById(R.id.fragment_content_2);

                    if(f2 != null && f2.isInLayout())
                    {
                        f2.setName(name);
                    }

                    Activity activity = getActivity();

                    if(activity != null)
                    {
                        Toast.makeText(activity,Toast.LENGTH_LONG).show();
                    }
                }
            });

            return view;


        }

    }

Fragment_2.Java

package com.example.fragmentexample;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Fragment_2 extends Fragment{

    View view;

    @Override
    public View onCreateView(LayoutInflater inflater,false);        
        return view;
    }

    public void setName(String name)
    {
        TextView txtName = (TextView) view.findViewById(R.id.txtViewResult);
        txtName.setText("Hi " + name);
    }

}

这是ScreenShot …

如何在Android中使用片段的更多相关文章

  1. html5 canvas合成海报所遇问题及解决方案总结

    这篇文章主要介绍了html5 canvas合成海报所遇问题及解决方案总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  2. Html5 video标签视频的最佳实践

    这篇文章主要介绍了Html5 video标签视频的最佳实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  3. HTML5在微信内置浏览器下右上角菜单的调整字体导致页面显示错乱的问题

    HTML5在微信内置浏览器下,在右上角菜单的调整字体导致页面显示错乱的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

  4. ios – containerURLForSecurityApplicationGroupIdentifier:在iPhone和Watch模拟器上给出不同的结果

    我使用默认的XCode模板创建了一个WatchKit应用程序.我向iOSTarget,WatchkitAppTarget和WatchkitAppExtensionTarget添加了应用程序组权利.(这是应用程序组名称:group.com.lombax.fiveminutes)然后,我尝试使用iOSApp和WatchKitExtension访问共享文件夹URL:延期:iOS应用:但是,测试NSURL

  5. Ionic – Splash Screen适用于iOS,但不适用于Android

    我有一个离子应用程序,其中使用CLI命令离子资源生成的启动画面和图标iOS版本与正在渲染的启动画面完美配合,但在Android版本中,只有在加载应用程序时才会显示白屏.我检查了config.xml文件,所有路径看起来都是正确的,生成的图像出现在相应的文件夹中.(我使用了splash.psd模板来生成它们.我错过了什么?这是config.xml文件供参考,我觉得我在这里做错了–解决方法在config.xml中添加以下键:它对我有用!

  6. ios – 无法启动iPhone模拟器

    /Library/Developer/CoreSimulator/Devices/530A44CB-5978-4926-9E91-E9DBD5BFB105/data/Containers/Bundle/Application/07612A5C-659D-4C04-ACD3-D211D2830E17/ProductName.app/ProductName然后,如果您在Xcode构建设置中选择标准体系结构并再次构建和运行,则会产生以下结果:dyld:lazysymbolbindingFailed:Symbol

  7. Xamarin iOS图像在Grid内部重叠

    heyo,所以在Xamarin我有一个使用并在其中包含一对,所有这些都包含在内.这在Xamarin.Android中看起来完全没问题,但是在Xamarin.iOS中,图像与标签重叠.我不确定它的区别是什么–为什么它在Xamarin.Android中看起来不错但在iOS中它的全部都不稳定?

  8. 在iOS上向后播放HTML5视频

    我试图在iPad上反向播放HTML5视频.HTML5元素包括一个名为playbackRate的属性,它允许以更快或更慢的速率或相反的方式播放视频.根据Apple’sdocumentation,iOS不支持此属性.通过每秒多次设置currentTime属性,可以反复播放,而无需使用playbackRate.这种方法适用于桌面Safari,但似乎在iOS设备上的搜索限制为每秒1次更新–在我的情况下太慢了.有没有办法在iOS设备上向后播放HTML5视频?解决方法iOS6Safari现在支持playbackRat

  9. 使用 Swift 语言编写 Android 应用入门

    Swift标准库可以编译安卓armv7的内核,这使得可以在安卓移动设备上执行Swift语句代码。做梦,虽然Swift编译器可以胜任在安卓设备上编译Swift代码并运行。这需要的不仅仅是用Swift标准库编写一个APP,更多的是你需要一些框架来搭建你的应用用户界面,以上这些Swift标准库不能提供。简单来说,构建在安卓设备上使用的Swiftstdlib需要libiconv和libicu。通过命令行执行以下命令:gitclonegit@github.com:SwiftAndroid/libiconv-libi

  10. Android – 调用GONE然后VISIBLE使视图显示在错误的位置

    我有两个视图,A和B,视图A在视图B上方.当我以编程方式将视图A设置为GONE时,它将消失,并且它正下方的视图将转到视图A的位置.但是,当我再次将相同的视图设置为VISIBLE时,它会在视图B上显示.我不希望这样.我希望视图B回到原来的位置,这是我认为会发生的事情.我怎样才能做到这一点?编辑–代码}这里是XML:解决方法您可以尝试将两个视图放在RelativeLayout中并相对于彼此设置它们的位置.

随机推荐

  1. bluetooth-lowenergy – Altbeacon库无法在Android 5.0上运行

    昨天我在Nexus4上获得了Android5.0的更新,并且altbeacon库停止了检测信标.似乎在监视和测距时,didEnterRegion和didRangeBeaconsInRegion都没有被调用.即使RadiusNetworks的Locate应用程序现在表现不同,一旦检测到信标的值,它们就不再得到更新,并且通常看起来好像信标超出了范围.我注意到的一点是,现在在logcat中出现以下行“B

  2. android – react-native动态更改响应者

    我正在使用react-native进行Android开发.我有一个视图,如果用户长按,我想显示一个可以拖动的动画视图.我可以使用PanResponder实现这一点,它工作正常.但我想要做的是当用户长按时,用户应该能够继续相同的触摸/按下并拖动新显示的Animated.View.如果您熟悉Google云端硬盘应用,则它具有类似的功能.当用户长按列表中的任何项目时,它会显示可拖动的项目.用户可以直接拖

  3. android – 是否有可能通过使用与最初使用的证书不同的证书对其进行签名来发布更新的应用程序

    是否可以通过使用与最初使用的证书不同的证书进行签名来发布Android应用程序的更新?我知道当我们尝试将这样的构建上传到市场时,它通常会给出错误消息.但有没有任何出路,比如将其标记为主要版本,指定市场中的某个地方?解决方法不,你不能这样做.证书是一种工具,可确保您是首次上传应用程序的人.所以总是备份密钥库!

  4. 如何检测Android中是否存在麦克风?

    ..所以我想在让用户访问语音输入功能之前检测麦克风是否存在.如何检测设备上是否有麦克风.谢谢.解决方法AndroidAPI参考:hasSystemFeature

  5. Android – 调用GONE然后VISIBLE使视图显示在错误的位置

    我有两个视图,A和B,视图A在视图B上方.当我以编程方式将视图A设置为GONE时,它将消失,并且它正下方的视图将转到视图A的位置.但是,当我再次将相同的视图设置为VISIBLE时,它会在视图B上显示.我不希望这样.我希望视图B回到原来的位置,这是我认为会发生的事情.我怎样才能做到这一点?编辑–代码}这里是XML:解决方法您可以尝试将两个视图放在RelativeLayout中并相对于彼此设置它们的位置.

  6. android – 获得一首歌的流派

    我如何阅读与歌曲相关的流派?我可以读这首歌,但是如何抓住这首歌的流派,它存放在哪里?解决方法检查此代码:

  7. android – 使用textShadow折叠工具栏

    我有一个折叠工具栏的问题,在展开状态我想在文本下面有一个模糊的阴影,我使用这段代码:用:我可以更改textColor,它可以工作,但阴影不起作用.我为阴影尝试了很多不同的值.是否可以为折叠文本投射阴影?

  8. android – 重用arm共享库

    我已经建立了armarm共享库.我有兴趣重用一个函数.我想调用该函数并获得返回值.有可能做这样的事吗?我没有任何头文件.我试过这个Android.mk,我把libtest.so放在/jni和/libs/armeabi,/lib/armeabi中.此时我的cpp文件编译,但现在是什么?我从objdump知道它的名字编辑:我试图用这个android.mk从hello-jni示例中添加prebuild库:它工作,但libtest.so相同的代码显示以下错误(启动时)libtest.so存在于libhello-j

  9. android – 为NumberPicker捕获键盘’Done’

    我有一个AlertDialog只有一些文本,一个NumberPicker,一个OK和一个取消.(我知道,这个对话框还没有做它应该保留暂停和恢复状态的事情.)我想在软键盘或其他IME上执行“完成”操作来关闭对话框,就像按下了“OK”一样,因为只有一个小部件可以编辑.看起来处理IME“Done”的最佳方法通常是在TextView上使用setonEditorActionListener.但我没有任何Te

  10. android – 想要在调用WebChromeClient#onCreateWindow时知道目标URL

    当我点击一个带有target=“_blank”属性的超链接时,会调用WebChromeClient#onCreateWindow,但我找不到新的窗口将打开的新方法?主页url是我唯一能知道的东西?我想根据目标网址更改应用行为.任何帮助表示赞赏,谢谢!

返回
顶部