有谁知道如何使用Robolectric测试以下设置?
包含ViewPager的片段,使用CursorLoader加载的数据.
使用下面的代码,CursorLoader永远不会被推入视图寻呼机的适配器中.我被await()
电话困住了.
EventsFragmentTest.java:
@RunWith(CustomRobolectricTestRunner.class)
public class EventsFragmentTest extends AbstractDbAndUiDriver
{
// which element in the view pager we are testing
private static final int TEST_INDEX = 0;
protected SherlockFragmentActivity mActivity;
protected EventsFragment_ mFragment;
@Override
@Before
public void setUp() throws Exception
{
// create activity to hold the fragment
this.mActivity = CustomRobolectricTestRunner.getActivity();
// create and start the fragment
this.mFragment = new EventsFragment_();
}
@Test
public void sanityTest()
{
// create an event
final Event event = this.createEvent();
// …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用针对Android选项卡的Rhodes实现签名捕获.我已经设法得到画布并随意涂鸦.但我无法将签名保存在所需位置.在signature_uri
采用默认位置为db/db-files/Image-XXXXXX.png
.
这是示例中的代码:
def signature_callback
if @params['status'] == 'ok'
#create signature record in the DB
signature = SignatureUtil.new({'signature_uri'=>@params['signature_uri']})
signature.save
puts "new Signature object: " + signature.inspect
end
Run Code Online (Sandbox Code Playgroud)
在控制台我得到:
APP| RHO serve: /app/Settings/signature_callback
I/APP ( 801): I 01/26/2012 11:36:20:236 0000032e APP| Params: {"status"=>"ok", "signature_uri"=>"db/db-files/Image_20120126113618375.png", "rho_callback"=>"1"}
I/APP ( 801): I 01/26/2012 11:36:20:238 0000032e APP| *******************ok****************
I/APP ( 801): I 01/26/2012 11:36:20:238 0000032e APP| %%%%%%%%%%%%%%%%%db/db-files/Image_20120126113618375.png%%%%%%%%%%%
I/APP ( 801): I 01/26/2012 11:36:20:239 0000032e APP| App error: can't convert Symbol into …
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试在我的Android应用程序中设置WiFi扫描,每隔30秒扫描一次WiFi接入点.
我已经使用Timer和TimerTask以我需要的间隔正确运行扫描.
但是我希望能够在用户按下按钮时停止并开始扫描,我当前无法停止然后重新启动Timer和TimerTask.
这是我的代码
TimerTask scanTask;
final Handler handler = new Handler();
Timer t = new Timer();
public void doWifiScan(){
scanTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
wifiManager.scan(context);
Log.d("TIMER", "Timer set off");
}
});
}};
t.schedule(scanTask, 300, 30000);
}
public void stopScan(){
if(scanTask!=null){
Log.d("TIMER", "timer canceled");
scanTask.cancel();
}
}
Run Code Online (Sandbox Code Playgroud)
所以Timer和Task启动正常并且扫描每30秒发生一次但是我不能让它停止,我可以停止Timer但是任务仍然发生并且scanTask.cancel()似乎也不起作用.
有一个更好的方法吗?或者我在Timer/TimerTask类中遗漏了什么?
我正在寻找一种方法来禁用我的地图片段的自动中心选定的标记功能.我仍然希望显示标记InfoWindow,但不要将整个地图置于我选择的标记上.
我一直在努力将我的应用程序更新为Material Design.
我有一个使用标签的应用程序.出于某种原因,每当我使用android:popupBackground来设置下拉菜单颜色时,它就会变得怪异.
我设置了一个带有标签的默认项目,并使用了以下主题,同样的事情发生了.有没有其他人有这个问题?我的应用程序是开源的,因此所有代码都可以在这里获得GitHub
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionDropDownStyle">@style/Dropdown</item>
</style>
<style name="Dropdown" parent="Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:popupBackground">#000</item>
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud) android android-appcompat android-actionbar android-actionbar-compat material-design
我想创建一个这样的页面.这7个按钮已经存在但是如果用户想要添加更多类别(按钮),那么他可以使用+按钮并使用-按钮删除.这个有什么想法或教程吗?
当我的应用程序安装并在后台运行200毫秒时,我需要以编程方式截取Android设备或模拟器,并将图像保存在我的计算机中.我已使用下面的代码实现了此过程,仅在我的应用程序位于前台时才有效.当我的应用程序也在后台时,我想截取屏幕截图.以下是我的代码:
public static Bitmap takeScreenshot(Activity activity, int ResourceID) {
Random r = new Random();
int iterator=r.nextInt();
String mPath = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
View v1 = activity.getWindow().getDecorView().findViewById(ResourceID);
v1.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v1.layout(0, 0, v1.getMeasuredWidth(), v1.getMeasuredHeight());
v1.setDrawingCacheEnabled(true);
final Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
Bitmap resultBitmap = Bitmap.createScaledBitmap(bitmap, 640, 480, false);
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
imageFile.mkdirs();
imageFile = new File(imageFile+"/"+iterator+"_screenshot.png");
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
resultBitmap.compress(CompressFormat.PNG, 100, bos);
byte[] bitmapdata = bos.toByteArray();
//write the bytes in file
FileOutputStream fos = …
Run Code Online (Sandbox Code Playgroud) 我一直试图在网上查找有关如何做到这一点的任何解决方案或示例,但无法找到类似我的问题的任何东西.
我有一个LinearLayout
我想Views
在ArrayList
数据更改时添加/删除的位置.
据我所知,唯一的方法是CustomView
通过扩展AdapterView
和使用来创建ArrayAdapter
.
不幸的是,我不理解正确的数据流来解决这个问题.
我在哪里指定CustomView
哪个View是容器?我可以只投CustomView
的LinearLayout
时候,我会已经实现了吗?
编辑:我强调 - 我不需要ListView
.我需要它CustomView
我为移动设备/平板电脑设计了一个网页.当我在移动/平板电脑浏览器中打开它时,复选框看起来很小,很难识别它是否被检查.我试过用css.但没用
我们如何增加移动/平板电脑浏览器网页的复选框大小?否则有什么解决方案吗?
我认为这是专家的问题.
我从ListView数据列表中调用getView()
了positon 超出界限的调用.
当我使用适配器过滤器时会发生这种情况 过滤器方法使用小于原始列表的过滤列表填充数据.
当新筛选的列表比先前 筛选的列表短时,似乎发生错误.我更改了代码,在越界时返回一个虚拟convertView,只是为了查看发出了多少这样的调用.publishResults()
getView()
这些是log
我记录的相关代码和消息:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// No logs here to keep ListView performance good
Log.d(TAG, "+ getView( position=" + position + ")");
ViewHolder holder;
if( position >= mData.size() ) {
// This code allows to see how many bad calls I get
Log.w(TAG, "position out of bounds!");
convertView = mInflater.inflate(mLayout, parent, false); …
Run Code Online (Sandbox Code Playgroud)