我有一个GridView.数据GridView是来自服务器的请求.
这是项目布局GridView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/analysis_micon_bg"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/half_activity_vertical_margin"
android:paddingLeft="@dimen/half_activity_horizontal_margin"
android:paddingRight="@dimen/half_activity_horizontal_margin"
android:paddingTop="@dimen/half_activity_vertical_margin" >
<ImageView
android:id="@+id/ranking_prod_pic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/ranking_rank_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/ranking_prod_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/ranking_prod_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我从服务器请求数据,获取图像URL并加载图像 Bitmap
public static Bitmap loadBitmapFromInputStream(InputStream is) {
return BitmapFactory.decodeStream(is);
}
public static Bitmap loadBitmapFromHttpUrl(String url) {
try {
return loadBitmapFromInputStream((InputStream) (new URL(url).getContent()));
} catch (Exception e) {
Log.e(TAG, e.getMessage());
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
并且getView(int …
这是地图
@Autowired
private Map<String, ISendableConverter> converters;
Run Code Online (Sandbox Code Playgroud)
和 ISendableConverter
public interface ISendableConverter {
ISendableMsg convert(BaseMessage baseMessage);
String getType();
}
Run Code Online (Sandbox Code Playgroud)
有几个类实现 ISendableConverter
我想converters通过使用spring Autowried 将它们注入变量.
类的实例作为值,方法的结果@Autowried作为键.
像这个
@Component
public class SendableVoiceMsgConverter implements ISendableConverter {
@Override
public ISendableMsg convert(BaseMessage baseMessage) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getType() {
return "VOICE";
}
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?如何?
public static void main(String[] args) throws IOException {
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "foxzen")
.put("node.name", "yu").build();
Client client = new TransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress("XXX.XXX.XXX.XXX", 9200));
// XXX is my server's ip address
IndexResponse response = client.prepareIndex("twitter", "tweet")
.setSource(XContentFactory.jsonBuilder()
.startObject()
.field("productId", "1")
.field("productName", "XXX").endObject()).execute().actionGet();
System.out.println(response.getIndex());
System.out.println(response.getType());
System.out.println(response.getVersion());
client.close();
}
Run Code Online (Sandbox Code Playgroud)
我从我的电脑访问服务器
curl -get http://XXX.XXX.XXX.XXX:9200/
Run Code Online (Sandbox Code Playgroud)
得到这个
{
"status" : 200,
"name" : "yu",
"version" : {
"number" : "1.1.0",
"build_hash" : "2181e113dea80b4a9e31e58e9686658a2d46e363",
"build_timestamp" : "2014-03-25T15:59:51Z",
"build_snapshot" : false,
"lucene_version" : "4.7"
},
"tagline" : …Run Code Online (Sandbox Code Playgroud) 我想通过使用reflect来设置类的属性,而我的类有一个List<Article>属性.
我只是得到List<Article>以下代码的泛型类型
Method[] methods = target.getClass().getMethods();
String key = k.toString(), methodName = "set" + key;
Method method = getMethod(methods, methodName);
if (Iterable.class.isAssignableFrom(method.getParameterTypes()[0])) {
// at there, i get the generics type of list
// how can i create a instance of this type?
Type type = getGenericsType(method);
}
public static Method getMethod(Method[] methods, String methodName) {
for (Method method : methods) {
if (method.getName().equalsIgnoreCase(methodName))
return method;
}
return null;
}
private static Type getGenericsType(Method method) { …Run Code Online (Sandbox Code Playgroud) 这些是我发现的东西,当Stringjava中的长度超过一个值时,它显示为奇数.
有我的测试代码
public static void main(String[] args) {
int length = 4096;
char[] chars = new char[length];
for (char c : chars) {
c = 'c';
}
String str = new String(chars);
System.out.println(str.length());
System.out.println(str);
}
Run Code Online (Sandbox Code Playgroud)
当我在我的计算机上运行代码时,我从控制台获得4096空格字符输出.
然后我将长度变量更改为4095,此时输出正确,4095个c字符.
但在另一台计算机上,输出不正确,除非长度变量小于2900.
我只是想不通为什么?
编辑
我想我发现了什么,我尝试在命令窗口再次运行它,即使长度值足够大,它的打印正确.
这对于eclipse的控制台似乎有些限制.
但我检查了我的eclipse控制台缓冲区大小,它的800000