例如:
public final class R {
public static final class raw {
public static final int yuri=0x7f040000;
}
}
Run Code Online (Sandbox Code Playgroud)
如何通过名称获取资源?不使用R.raw.yuri =(int)
我正在onListItemClick事件中的listactivity中创建一个弹出窗口.
LayoutInflater inflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View pop = inflater.inflate(R.layout.popupcontact, null, false);
ImageView atnot = (ImageView)pop.findViewById(R.id.aNot);
height = pop.getMeasuredHeight();
width = pop.getMeasuredWidth();
Log.e("pw","height: "+String.valueOf(height)+", width: "+String.valueOf(width));
atnot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pw.dismiss();
}
});
pw = new PopupWindow(pop, width, height, true);
// The code below assumes that the root container has an id called 'main'
//pw.showAtLocation(v, Gravity.CENTER, 0, 0);
pw.showAsDropDown(v, 10, 5);
Run Code Online (Sandbox Code Playgroud)
现在,高度和宽度变量应该是用于弹出窗口(popupcontact)的布局的高度和宽度.但他们返回0.我想这是因为布局尚未呈现.有没有人有线索,如何控制弹出窗口的大小而不需要使用绝对像素数?
有没有办法从Android中的ListView中获取第一个可见的View?
我可以获取支持适配器中第一个View的数据,但似乎我无法获得ListView中的第一个View.
我想在滚动操作完成后更改第一个可见视图.我知道我不应该保存对视图的引用.
我是android的新手.我有基于客户端服务器的应用.服务器每隔一分钟就会继续向客户端发送更新通知,在客户端,我的应用程序会收到这些更新并使用Toast显示它.但现在我的问题是每当我的客户端应用程序进入后台服务器继续发送更新通知,我的客户端显示它就好像应用程序在前台.我没有得到如何检查该应用程序是否在后台运行.
我们正在开发一个应用程序,我们需要同时从多个视图中捕获MotionEvent.当我们尝试这样做时,Android只会将事件调度到第一个触摸的视图,并且当同时触摸另一个视图时,它仅在第一个视图上给出一个ACTION_POINTER_DOWN,即使指针坐标超出其边界而在其他视图内部也是如此.
我们有什么方法可以将事件分派到每个触摸的视图(在单独的OnTouch调用中)?
我们认为从父视图中截取触摸事件然后手动将它们分派到每个视图可能会起作用,但即使这样做,也不适合我们想要实现的目标.有没有更简单的方法?
我正在使用
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, DURATION, broadcast);
Run Code Online (Sandbox Code Playgroud)
计划仅在设备未处于睡眠状态时才应执行的重复任务.据我了解AlarmManager上的API,一旦设备从睡眠状态唤醒,就会调用intent.
现在Android设备什么时候睡着了?为了测试,我将持续时间设置为两分钟,并将设备连接到我的机器.现在我正在看logcat,每隔两分钟它就会吐出我的调试信息.
我一直认为停用屏幕意味着设备开始睡眠.或者我正在查看调试输出,以防止设备休眠?我也断开了USB连接,并在半小时后查看了日志,即使显示器黑暗超过15分钟,我也可以看到我的计时器代码.
如何验证命令不再执行的时间以及AlarmManager文档中的睡眠是什么?设备开始睡眠时有没有办法从logcat输出中看到?
我在TabActivity中动态创建选项卡.有没有一种简单的方法来询问现有标签的数量?
我是Android仪表单元测试的新手.我有一个看起来像这样的简单测试.这是仪器化测试; 在我真正编写一个实际的仪器测试之前,我只想测试一个简单的测试:
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AddressBookKeepingInstrumentedTest {
public static final String TEST_STRING = "This is a string";
public static final long TEST_LONG = 12345678L;
@Test
public void test_simple() {
assertEquals(2,1+1);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到以下错误:
junit.framework.AssertionFailedError: No tests found in com.example.myfirstapp.AddressBookKeepingInstrumentedTest
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1729)
Tests ran to completion.
Run Code Online (Sandbox Code Playgroud)
Gradle构建在此之前成功通过.任何想法为什么会这样?
我有一个扩展ListView的活动.我用查询结果填充我的列表到sqlite数据库.list元素由start_time,end_time,client_name和status组成.这些是我需要为每个列表项显示的4位信息.
我的问题是:我可以为这个ListView项目分配隐藏的元素吗?
例如,我想存储该ListView项的数据库行的_id字段,这样当我单击它时,我可以根据该数据库行的数据启动一个新活动.
编辑
我用来从我的光标填充列表的代码:
String[] columns = new String[] {VisitsAdapter.KEY_CLIENT_FULL_NAME, VisitsAdapter.KEY_STATUS,VisitsAdapter.KEY_CLIENT_START_TIME, VisitsAdapter.KEY_CLIENT_END_TIME};
// the XML defined views which the data will be bound to
int[] to = new int[] { R.id.name_entry,R.id.number_entry,R.id.start_time_display,R.id.end_time_display };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(HomeScreen.this, R.layout.list_element, cur, columns, to);
Run Code Online (Sandbox Code Playgroud)
其中R.layout.list_item是我的列表项的XML.我来自PHP/HTML背景,所以我通常会在这里做一个隐藏字段来保存我的_id值,然后我可以在单击列表项后访问它.我可以在android中做类似的事吗?我可以在我的xml布局中放置一个隐藏的_id字段吗?
我无法找到Retrofit默认行为的好解释.
如果Okhttp在类路径上,它将自动使用.但据我所知,默认的HttpResponseCache为null.
我是否需要使用Retrofit和Okhttp显式启用缓存?
android ×10
alarmmanager ×1
http ×1
http-caching ×1
layout ×1
okhttp ×1
popup ×1
resources ×1
retrofit ×1
size ×1
tabactivity ×1
unit-testing ×1