我有一个带有自定义对象的ArrayList.我想在这个ArrayList中搜索字符串.
对象的类看起来像这样:
public class Datapoint implements Serializable {
private String stateBased;
private String name;
private String priority;
private String mainNumber;
private String groupadress;
private String dptID;
public Datapoint(){
}
public String getMainNumber() {
return mainNumber;
}
public void setMainNumber(String mainNumber) {
this.mainNumber = mainNumber;
}
public String getName() {
return name;
}
..and so on
Run Code Online (Sandbox Code Playgroud)
我知道如何在ArrayList中搜索字符串但是如何使用我的自定义对象在ArrayList中执行此操作:
ArrayList<String> searchList = new ArrayList<String>();
String search = "a";
int searchListLength = searchList.size();
for (int i = 0; i < searchListLength; i++) {
if …Run Code Online (Sandbox Code Playgroud) 我添加了一个片段
transaction.add(R.id.content, fragment, null);
Run Code Online (Sandbox Code Playgroud)
我需要从这个开始新的片段.但要做到这一点,我需要知道第一个片段的容器视图ID(在我的例子中是R.id.content).我怎么能得到这个?
我可以直接使用这个id,但我想片段不应该知道有关父活动的这类细节.例如,在这种情况下,不可能在另一个活动中使用此片段.
可能是从另一个"起始"片段是一个不好的做法,所有片段处理逻辑应该由活动本身处理?但是创建好的片段序列相互启动似乎非常有用(例如detalView-> moreDetailView-> evenMoreDetailView).
我正在开发一个具有以下必要条件的应用程序:如果设备中插入了耳机并且用户将其删除,我需要将所有流静音.要做到这一点,我需要听广播AudioManager.ACTION_AUDIO_BECOMING_NOISY.还行吧!这里没问题.
但是当用户再次插入耳机时,我需要取消静音设备.但是没有AudioManager.ACTION_AUDIO_BECOMING_NOISY相反的广播.我不知道耳机何时再次插上.
一个解决办法是定期检查是否AudioManager.isWiredHeadsetOn()是true但这似乎并没有得到很好的解决了我.
有没有办法检测用户何时在设备上插入耳机?
编辑:我试图用Intent.ACTION_HEADSET_PLUG这种方式,但它没有用.
在manifest.xml中我放了:
<receiver android:name=".MusicIntentReceiver" >
<intent-filter>
<action android:name="android.intent.action.HEADSET_PLUG" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
以下是我的代码MusicIntentReceiver.java:
public class MusicIntentReceiver extends BroadcastReceiver {
public void onReceive(Context ctx, Intent intent) {
AudioManager audioManager = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
Log.d("Let's turn the sound on!");
//other things to un-mute the streams
}
}
}
Run Code Online (Sandbox Code Playgroud)
尝试其他任何解决方案?
我正在使用ActionBarSherlock开发一个App
菜单中的一个项目是矩形图像.看它的xml:
<item
android:id="@+id/kapturar_action"
android:showAsAction="always"
android:icon="@drawable/camera_action_icon"
android:title="@string/kapturar" />
<item
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.问题是SDK 4.3似乎只接受方形图像(这是我的假设,我不确定),图标以一种奇怪的方式显示,保留了似乎是"最大宽度"的属性.
请参阅版画屏幕
Android 2.2 - 模拟器:

Android 4.1.2 - 三星Galaxy S3 Mini:

Android 4.3 - Nexus 4:

我仔细检查了drawables,我认为一切都是正确的.我已经定义了MDPI,HDPI和XHDPI图像.
任何人都可以肯定在菜单项目中不可能使用矩形抽屉吗?有没有办法解决Android 4.3中的问题,保留向后兼容?
通过阅读它们,我了解到 android 类是一个仅为方便起见的实用程序类,并且不提供任何SimpleDateFormat不提供的东西。android类有什么意义吗?使用它是否是更好的做法(如果是,为什么)?我的目标是在 Android 应用程序中显示 Date 对象(显然)。这里是:
private Date date;
public String getDateString(String formatStr){
return new SimpleDateFormat(formatStr).format(date);
}
Run Code Online (Sandbox Code Playgroud)
像这样使用 android.text.format.DateFormat 会更好吗:
public String getDateString(String formatStr){
return android.text.format.DateFormat.format(formatStr, date);
}
Run Code Online (Sandbox Code Playgroud)
或者也许两者都不是,但最好采用不同的方式?提前致谢。
情况如下:我有两个项目.让我们说a LibraryProject和a MainProject.该MainProject引用LibraryProject作为库.
我有一个活动LibraryProject,需要发现是否MainProject定义了一个特定的drawable,让我们说"logo.png"(认为徽标图像必须由每个`MainProject定义,而不是由LibraryProject定义.
如何在一个活动中LibraryProject发现文件夹中是否MainProject有此图像res/drawable?
显然我试图看看是否 R.drawable.logo != 0(或它的变化),但是如你所知,这行不会编译,因为图像不在res/drawable文件夹中LibraryProject.
我也试过getResources().getIdentifier("logo", "drawable", null) != 0但是这个布尔表达式总是返回false,因为它.getIdentifier()总是返回零.
任何的想法?
我有这个Mongoose Schema.
var mongoose = require ('mongoose')
, dev = require ('../db').dev ();
var schema = new mongoose.Schema ({
date: {
type: Date,
default: Date.now
},
company: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Company'
},
questionnaire: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Questionnaire'
}
});
module.exports = dev.model ('Survey', schema);
Run Code Online (Sandbox Code Playgroud)
我只想查找具有特定公司ID的调查.我怎么做?我试过(使用我的Express处理程序):
app.get ('/survey', function (req, res) {
Survey.find ({ company: req.query.company }).populate ('questionnaire').exec (function (err, surveys) {
return res.json (surveys);
});
});
Run Code Online (Sandbox Code Playgroud) 我的团队正在开发具有UITabBarController的应用程序。我们正在使用Storyboard开发界面和流程。
由于我们是一个团队,因此我们不能将所有流程都放在一个故事板上,因为这将导致与SVN同步的问题。因此,解决方案是将每个选项卡的流程放在一个不同的情节提要文件中。
如我在本教程中所见,当我可以创建一个对象进行连接(例如,一个按钮)时,故事板之间的连接就不是问题。
但是,当我将UITabBarController放在一个情节提要板中时,无法以编程方式设置将为tabBar的每个按钮显示的情节提要板来管理底部栏的视图元素(tabBar本身)。
现在,我在同一.storyboard文件中拥有TabBar和UIViewControllers,如下所示:

因此,我需要通过一个UITabBarController连接不同的故事板。怎么做?
我正在使用Dia制作一个序列图,我需要制作一个有两个(或更多)执行规范的生命线,如下图所示:
(我想要的是在绿色圆圈内)
我怎样才能做到这一点?
我正在尝试计算其中包含单个航点的航线的总距离,但不知何故,我的代码仅返回到第一航点而不是总距离的距离.
这是我的代码:
function calcRoute(homebase,from,to,via){
var start = from;
var end = to;
var wypt = [ ];
wypt.push({
location:via,
stopover:true});
var request = {
origin:start,
destination:end,
waypoints:wypt,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.METRIC
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var distance = response.routes[0].legs[0].distance.text;
var time_taken = response.routes[0].legs[0].duration.text;
var calc_distance = response.routes[0].legs[0].distance.value;
}
});
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码更改UISearchBar中取消按钮的背景.
for( UIView *subview in self.searchBar.subviews ){
if ([subview isKindOfClass:[UIButton class]]) {
[(UIButton *)subview setEnabled:YES];
[(UIButton *)subview setTitle:@"New Button Text" forState:UIControlStateNormal];
((UIButton *)subview).tintColor = [UIColor colorWithRed:4/255.0 green:119/255.0 blue:152/255.0 alpha:1.0];
}
}
Run Code Online (Sandbox Code Playgroud)
问题是这个代码在iOS7中不起作用!UISearchBar中视图结构发生了哪些变化?
编辑:在这里测试,这是UISearchBar的新层次结构:
UISearchBar:
---UIView:
------UISearchBarBackground
------UISearchBarTextField
------UINavigationButton
Run Code Online (Sandbox Code Playgroud)
问题是我无法测试if ([sub isKindOfClass:[UINavigationButton class]]).此行抛出编译错误:Use of undeclared identifier: UINavigationButton
android ×4
java ×2
objective-c ×2
android-date ×1
android-view ×1
api ×1
arraylist ×1
cocoa-touch ×1
containers ×1
dia ×1
express ×1
google-maps ×1
ios7 ×1
iphone ×1
javascript ×1
mongodb ×1
mongoose ×1
node.js ×1
search ×1
uisearchbar ×1
uistoryboard ×1
uml ×1
xcode ×1