Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

5
片段内的onCreateOptionsMenu
我已放置setHasOptionsMenu(true)在内部onCreateView,但仍无法调用onCreateOptionsMenu内部片段。 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); return inflater.inflate(R.layout.facesheet, container, false); } 下面是我的onCreateOptionsMenu代码。 @Override public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { getSupportMenuInflater().inflate(R.menu.layout, menu); return (super.onCreateOptionsMenu(menu)); } 我收到的错误消息: 该方法onCreateOptionsMenu(Menu)类型片段的必须重写或实现的超类型方法。

18
从Windows 7 x64通过USB经由“ adb设备”无法看到Nexus 7
我做的很明显-从最新的Android SDK安装了USB驱动程序,并在平板电脑中打开了USB调试功能。 当的Nexus 7连接,该设备显示了在Windows 设备管理器为“Android手机” /“Android的综合亚设备”,以显示驱动程序版本6.0.0.0的属性,所以在安装正确的驱动程序和工作。 这也证明该设备处于USB调试模式,因为如果不是,它将显示在Windows的“便携式设备” /“ Nexus 7”下。 问题是adb devices没有显示任何设备,Eclipse也(毫不奇怪)也没有提供Nexus 7作为运行应用程序的硬件设备。 我已经重启了两个设备,但没有任何效果。 我唯一能弄清楚的调试是enable ADB_TRACE=all,但这告诉我什么: mkh@MULE ~/AppData/Local/Android/android-sdk/platform-tools $ export ADB_TRACE=all mkh@MULE ~/AppData/Local/Android/android-sdk/platform-tools $ adb devices system/core/adb/adb.c::main():Handling commandline() system/core/adb/adb_client.c::adb_query():adb_query: host:devices system/core/adb/adb_client.c::_adb_connect():_adb_connect: host:version system/core/adb/sysdeps_win32.c::socket_loopback_client():socket_loopback_client: port 5037 type tcp => fd 100 system/core/adb/transport.c::writex():writex: fd=100 len=4: 30303063 000c system/core/adb/transport.c::writex():writex: fd=100 len=12: 686f73743a76657273696f6e host:version …
182 android  adb  sideloading 

8
Android:具有多个可点击按钮的ListView元素
我ListView在列表中的每个元素都包含一个TextView和两个不同的Button的地方。像这样: ListView -------------------- [Text] [Button 1][Button 2] -------------------- [Text] [Button 1][Button 2] -------------------- ... (and so on) ... 使用此代码,我可以OnItemClickListener为整个商品创建一个: listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> list, View view, int position, long id) { Log.i(TAG, "onListItemClick: " + position); } } }); 但是,我不希望整个项目都可单击,而只希望每个列表元素具有两个按钮。 所以我的问题是,如何使用以下参数为这两个按钮实现onClickListener: int button (已单击元素的哪个按钮) int position (这是列表中单击按钮的元素) …
182 android  listview  button 

3
使用ViewPager的Android.app片段与android.support.v4.app?
我对Android支持库,片段以及作为一个具体示例的ViewPager类有疑问。我的意图是创建一个功能与Android Developer网站(http://developer.android.com/training/animation/screen-slide.html或http://developer.android.com/ training / implementing-navigation / lateral.html)。在研究他们的代码时,我注意到他们利用了该android.support.v4.app库,根据我的研究,该库是访问ViewPager该类的唯一方法。 在我的情况下,我对向后兼容性没有兴趣。最低API级别是14(冰淇淋三明治),构建目标是4.2软糖。以最简单的形式,我的应用程序执行的功能与我在Android开发人员网站上链接的第二个演示程序完全相同-只需在三个包含内容的选项卡之间滑动即可。 我读过的所有文章/帖子/答案似乎都非常支持v4支持库。现在是我的问题,尽管问题long之以鼻: 构造应用程序的最佳方法是什么-使用android.support.v4.app,从而使用SupportFragments,或使用其中提供的Fragments- android.app为什么? 如果“碎片来源” android.app是解决之道,那么最佳的解决方法是ViewPagers什么? 如果SupportFragments最适合该任务,我估计它们具有与其他功能相同的功能-那么将它们完全包含在内部的目的是什么android.app? 希望有一个更清晰的了解的人可以给我一些澄清,因为我感到困惑。

7
带有AppCompat-v7的工具栏和上下文操作栏
我正在使用Lollipop和AppCompat-v7库中引入的新添加的工具栏。我按照本指南设置工具栏时,发现,当您调用将弹出上下文操作栏的内容(例如突出显示要复制/粘贴的文本)时,它将在页面上向下推工具栏。您可以在页面底部的图像中看到我在说什么: 因此,基本上,我是这样设置的。我在与包含标签一起使用的xml文件中定义了工具栏: <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary"/> 然后,我将其实例化为: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/root" tools:context=".MainActivity"> <include layout="@layout/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content"/> <!-- Rest of view --> </LinearLayout> 在代码中,我将其设置如下: // On Create method of activity: Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); 有谁知道如何使Contextual ActionBar出现在工具栏的上方?

11
在Android中从上下文获取活动
这个让我难过。 我需要从自定义布局类中调用一个活动方法。问题是我不知道如何从布局中访问活动。 ProfileView public class ProfileView extends LinearLayout { TextView profileTitleTextView; ImageView profileScreenImageButton; boolean isEmpty; ProfileData data; String name; public ProfileView(Context context, AttributeSet attrs, String name, final ProfileData profileData) { super(context, attrs); ...... ...... } //Heres where things get complicated public void onClick(View v) { //Need to get the parent …

13
在Android上将字符串转换为整数
如何将字符串转换为整数? 我有一个文本框,我让用户输入一个数字: EditText et = (EditText) findViewById(R.id.entry1); String hello = et.getText().toString(); 并将该值分配给字符串hello。 我想将其转换为整数,以便获得他们键入的数字;稍后将在代码中使用它。 有没有办法得到EditText一个整数?那会跳过中间人。如果不是,则将字符串转换为整数就可以了。

10
自定义复选框图片Android
有没有一种简单的方法可以将自定义图像用于复选框?我想复制gmail的“加星标”行为。因此,我想有一个复选框,当选中该复选框时,它是一个实心星星。如果未选中,则为空星。我是否必须使用imageview并自己做自己的逻辑?
182 android  checkbox 

13
如何在Fragment中使用数据绑定
我正在尝试遵循Google官方文档中的数据绑定示例 https://developer.android.com/tools/data-binding/guide.html中的 除了我试图将数据出价应用于片段,而不是活动。 我目前在编译时遇到的错误是 Error:(37, 27) No resource type specified (at 'text' with value '@{marsdata.martianSols}. onCreate 片段看起来像这样: @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); MartianDataBinding binding = MartianDataBinding.inflate(getActivity().getLayoutInflater()); binding.setMarsdata(this); } onCreateView 片段看起来像这样: @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.martian_data, container, false); …

3
“ ArrayAdapter要求资源ID为TextView” xml问题
尝试将我的视图设置为显示要显示ListView的文件(文本文件)时出现错误。我很确定它与xml有关。我只想显示来自的信息this.file = fileop.ReadFileAsList("Installed_packages.txt");。我的代码: public class Main extends Activity { private TextView tv; private FileOperations fileop; private String[] file; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.fileop = new FileOperations(); this.file = fileop.ReadFileAsList("Installed_packages.txt"); setContentView(R.layout.main); tv = (TextView) findViewById(R.id.TextView01); ListView lv = new …

18
如何使WRAP_CONTENT在RecyclerView上工作
我有一个DialogFragment包含RecyclerView(卡片列表)的。 其中RecyclerView一个或多个CardViews可以具有任意高度。 我想DialogFragment根据CardViews其中包含的高度给它正确的高度。 通常情况下,这将是简单的,我会成立wrap_content的RecyclerView这个样子。 <android.support.v7.widget.RecyclerView ... xmlns:tools="http://schemas.android.com/tools" android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:clickable="true" android:scrollbars="vertical" > </android.support.v7.widget.RecyclerView> 因为我使用的是RecyclerView这不起作用,请参见: https://issuetracker.google.com/issues/37001674 和 嵌套的回收站视图高度不包含其内容 在这两个页面上,人们都建议扩展LinearLayoutManager和覆盖onMeasure() 我首先使用了第一个链接中提供的LayoutManager: public static class WrappingLayoutManager extends LinearLayoutManager { public WrappingLayoutManager(Context context) { super(context); } private int[] mMeasuredDimension = new int[2]; @Override public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) …

26
找不到名称为“默认”的Android Studio Gradle配置
我在使用Android Studio(0.1.5)编译应用程序时遇到问题。该应用程序使用2个库,其中包括以下内容: settings.gradle include ':myapp',':library',':android-ColorPickerPreference' build.gradle buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.4' } } apply plugin: 'android' dependencies { compile files('libs/android-support-v4.jar') compile project(':library') compile project(':android-ColorPickerPreference') } android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 7 targetSdkVersion 16 } } 编译时收到以下消息: Gradle: A problem occurred configuring …

14
为什么使用adb时无法访问数据文件夹?
我使用adb和以下命令连接了我的实时设备: C:\>adb -s HT829GZ52000 shell $ ls ls sqlite_stmt_journals cache sdcard etc system sys sbin proc logo.rle init.trout.rc init.rc init.goldfish.rc init default.prop data root dev $ cd data cd data $ ls ls opendir failed, Permission denied 看到访问被拒绝,我感到很惊讶。为什么我不能使用这样的命令行浏览目录? 如何在手机上获得root访问权限?
181 android  adb 


1
改造2-动态网址
使用Retrofit 2,您可以在服务方法的注释中设置完整的URL,例如: public interface APIService { @GET("http://api.mysite.com/user/list") Call<Users> getUsers(); } 但是,在我的应用程序中,我的Web服务的URL在编译时未知,该应用程序在下载的文件中检索它们,因此我想知道如何将Retrofit 2与完整的动态URL结合使用。 我试图设置一个完整的路径,如: public interface APIService { @GET("{fullUrl}") Call<Users> getUsers(@Path("fullUrl") fullUrl); } new Retrofit.Builder() .baseUrl("http://api.mysite.com/") .build() .create(APIService.class) .getUsers("http://api.mysite.com/user/list"); // this url should be dynamic .execute(); 但是在这里,Retrofit并未看到该路径实际上是完整的URL,而是试图下载 http://api.mysite.com/http%3A%2F%2Fapi.mysite.com%2Fuser%2Flist 关于如何将Retrofit与此类动态url一起使用的任何提示? 谢谢
181 android  retrofit 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.