在xml中,您可以在TextView中将文本的左侧,右侧,底部或顶部设置为drawable.有没有办法通过代码设置/更改此drawable?
我已经添加了一种风格
<style name="myRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:minHeight">32dp</item>
<item name="android:maxHeight">32dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然而,不是缩放星星,我收到了星星:
有没有办法改变星星的大小?
我有一个扩展LinearLayout的自定义视图.我已经实现了onSaveInstanceState()和onRestoreInstanceState()来保存当前的视图状态.但是,不采取任何行动.当我在这两种方法中放置一个日志时,Log Cat中也没有任何内容.我认为这两种方法甚至都没有被调用.任何人都可以解释问题在哪里?谢谢.
@Override
public Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.onSaveInstanceState());
bundle.putInt("currentPage", currentPage);
return bundle;
}
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
currentPage = bundle.getInt("currentPage");
Log.d("State", currentPage + "");
super.onRestoreInstanceState(bundle.getParcelable("instanceState"));
return;
}
super.onRestoreInstanceState(state);
}
Run Code Online (Sandbox Code Playgroud) 我使用distanceBetween()
Location类来计算两点之间的距离,如下所示:
private float getDistanceInMiles(GeoPoint p1, GeoPoint p2) {
double lat1 = ((double)p1.getLatitudeE6()) / 1e6;
double lng1 = ((double)p1.getLongitudeE6()) / 1e6;
double lat2 = ((double)p2.getLatitudeE6()) / 1e6;
double lng2 = ((double)p2.getLongitudeE6()) / 1e6;
float [] dist = new float[1];
Log.i("destination coordinates", "Latitude:" + lat2 + ", Longitude: " + lng2);
Location.distanceBetween(lat1, lng1, lat2, lng2, dist);
return dist[0] * 0.000621371192f;
}
Run Code Online (Sandbox Code Playgroud)
文档说distanceBetween()"计算两个位置之间的近似距离,以及它们之间最短路径的初始和最终方位." 但是,distanceBetween()和真实GPS设备或Google Navigation应用程序返回的结果之间的差异非常大.例如,我的方法将返回6.2英里,而谷歌地图显示相同位置10英里.我仔细检查起点p1和终点p2的坐标,它们似乎是正确的.这是distanceBetween()方法的工作原理还是我做错了什么?顺便说一下,有没有办法使用Google Place API来检索距离作为JSON响应?
Google地图计算的距离:6.1英里
结果
Location.distanceBetween(41.742964, -87.995971, 41.811511, -87.967923, dist) is
Run Code Online (Sandbox Code Playgroud)
4.947700
我使用Jsoup从URL获取页面.我可以使用以下代码行提取某些id的链接:
Elements links = doc.select("a[href]#title0");
Run Code Online (Sandbox Code Playgroud)
如果我只知道其ID的一部分,例如'title',我该如何找到这些元素.我知道我可以找到所有与href 的链接,然后遍历'链接'并检查它的id是否包含'title'子字符串,但是我想避免这种方法.有没有办法过滤选择器中的链接,并检查它的id是否包含'title'子串?
我试图ViewPager
通过在其中实现两个方法来保存当前状态(当前位置等)PagerAdapter
:restoreState()
和saveState()
.但是,在我的情况下,它们似乎无法正常工作.我做错了什么?
@Override
public Parcelable saveState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.saveState());
bundle.putInt("stateToSave", position);
return bundle;
}
@Override
public void restoreState(Parcelable state, ClassLoader c) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
position = bundle.getInt("stateToSave");
super.restoreState(bundle.getParcelable("instanceState"), c);
return;
}
super.restoreState(state, c);
}
Run Code Online (Sandbox Code Playgroud) 我正在开发我的第一个使用RestKit 0.2和Core Data的iOS应用程序.大部分时间我都遵循这个伟大的教程http://www.alexedge.co.uk/blog/2013/03/08/introduction-restkit-0-20/ 但是它不符合我的要求,因为它描述了嵌入式JSON对象和我需要创建单独的对象.以下是我的应用结构的简化方案:
JSON响应:
"application": [
{
"appId": "148",
"appName": …
.
.
.
(more attributes)
}
],
"image": [
{
"imgId": "308",
"appId": "148",
"iType": "screenshot",
"iPath": ..
.
.
.
},
{
"imgId": "307",
"appId": "148",
"iType": "logo",
"iPath": …
.
.
.
}
]
Run Code Online (Sandbox Code Playgroud)
我创建了一个包含两个实体的数据模型,并以一个应用程序可能有多个图像而一个图像可能只属于一个应用程序的方式设置它们之间的关系:
我使用了mogenerator来创建实体代表的类.
我可以使用以下代码将实体成功映射到Application对象:
NSDictionary *parentObjectMapping = @{
@"appId" : @"appId"
};
// Map the Application object
RKEntityMapping *applicationMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([Application class]) inManagedObjectStore:managedObjectStore];
applicationMapping.identificationAttributes = @[ @"appId" ];
[applicationMapping addAttributeMappingsFromDictionary:@{
@"appName" …
Run Code Online (Sandbox Code Playgroud) 我有一个列表视图,当我选择一个项目时,它会填充一个详细信息视图.我想通过将其更改为绿色来显示列表视图中选择的项目.麻烦的是,在我点击同一项目两次之前,所选项目不会显示为绿色.我在选中的项目上做错了什么,使其在单击项目两次之前不会变为绿色?这是我的xml选择器文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Active list item -->
<item android:state_selected="true"
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/lv_bg_selected" />
<!-- Inactive list item -->
<item android:state_selected="false"
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/lv_bg_unselected_state" />
<!-- Pressed list item -->
<item android:state_pressed="true"
android:drawable="@drawable/lv_bg_pressed_state" />
</selector>
Run Code Online (Sandbox Code Playgroud)
并在onListitemClick:
@Override
public void onListItemClick(ListView l, View v, int position, long id)
{
.
.
.
v.setSelected(true);
.
.
.
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用setContentView(R.layout.activityA)方法设置布局的A活动.activityA布局包含customView.我的customView有一堆setter和getter.如何从A活动中访问它们?当我在acitivity A中创建一个customView实例时,它可以工作,但是customView创建了两次:一次是从setContentView创建的,第二次是我创建它的新实例.有没有其他方法来访问这些方法?请指教.谢谢.
我有一个String(文件名): s_113_2.3gp
如何提取第二个下划线后出现的数字?在这种情况下它是' 2
'但在某些情况下可以是几位数.
此外,第一个下划线后出现的位数也可能不同,因此该String的长度不是恒定的.
android ×8
regex ×2
android-view ×1
cocoa-touch ×1
core-data ×1
google-maps ×1
ios ×1
java ×1
json ×1
jsoup ×1
php ×1
restkit ×1
textview ×1