- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我目前正在制作显示 ListView 的简单应用程序,点击它后应该会转到另一个显示所选项目详细信息的 Activity 。但是,当我单击时,应用程序崩溃了。我决定使用包含描述字符串数组的资源 XML 文件。
我已经完成更改,现在可以在 ListView 中单击我的项目并且应用程序不会崩溃。但是,字符串数组不会显示在新 Activity 中。
我做了更多更改,因为我意识到我没有在细节类中设置 toydespos。我现在的问题是 String 只显示了一部分
您会在我的资源文件中看到这不是完整的字符串数组。
这是我目前的错误日志:
06-19 20:51:48.504 22289-22289/? I/zygote: Not late-enabling -Xcheck:jni (already on)
06-19 20:51:48.566 22289-22289/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
06-19 20:51:48.952 22289-22289/com.example.littlegrace.puppydex I/InstantRun: starting instant run server: is main process
06-19 20:51:49.282 22289-22316/com.example.littlegrace.puppydex D/OpenGLRenderer: HWUI GL Pipeline
06-19 20:51:49.346 22289-22305/com.example.littlegrace.puppydex I/zygote: Background concurrent copying GC freed 5689(2MB) AllocSpace objects, 0(0B) LOS objects, 55% free, 1210KB/2MB, paused 8.132ms total 66.730ms
06-19 20:51:49.463 22289-22316/com.example.littlegrace.puppydex I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
06-19 20:51:49.464 22289-22316/com.example.littlegrace.puppydex I/OpenGLRenderer: Initialized EGL, version 1.4
06-19 20:51:49.464 22289-22316/com.example.littlegrace.puppydex D/OpenGLRenderer: Swap behavior 1
06-19 20:51:49.464 22289-22316/com.example.littlegrace.puppydex W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
06-19 20:51:49.464 22289-22316/com.example.littlegrace.puppydex D/OpenGLRenderer: Swap behavior 0
06-19 20:51:49.487 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglCreateContext: 0xe5085180: maj 3 min 1 rcv 4
06-19 20:51:49.525 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:51:49.529 22289-22316/com.example.littlegrace.puppydex E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
06-19 20:51:49.531 22289-22316/com.example.littlegrace.puppydex E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
06-19 20:51:49.618 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:51:50.908 22289-22289/com.example.littlegrace.puppydex V/StudioProfiler: StudioProfilers agent attached.
06-19 20:51:50.972 22289-22357/com.example.littlegrace.puppydex V/StudioProfiler: Acquiring Application for Events
06-19 20:51:51.001 22289-22289/com.example.littlegrace.puppydex V/StudioProfiler: Transformed class: java/net/URL
06-19 20:51:51.002 22289-22289/com.example.littlegrace.puppydex W/zygote: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
06-19 20:51:51.395 22289-22289/com.example.littlegrace.puppydex V/StudioProfiler: Memory control stream started.
06-19 20:51:53.049 22289-22363/com.example.littlegrace.puppydex V/StudioProfiler: Live memory tracking disabled.
06-19 20:51:53.054 22289-22363/com.example.littlegrace.puppydex V/StudioProfiler: Live memory tracking enabled.
06-19 20:51:53.055 22289-22363/com.example.littlegrace.puppydex V/StudioProfiler: JNIEnv not attached
06-19 20:51:53.275 22289-22363/com.example.littlegrace.puppydex V/StudioProfiler: Loaded classes: 5350
06-19 20:51:53.424 22289-22363/com.example.littlegrace.puppydex V/StudioProfiler: Tracking initialization took: 369734510ns
06-19 20:51:54.877 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:51:54.881 22289-22397/com.example.littlegrace.puppydex E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
06-19 20:51:54.882 22289-22397/com.example.littlegrace.puppydex I/chatty: uid=10081(com.example.littlegrace.puppydex) hwuiTask1 identical 3 lines
06-19 20:51:54.882 22289-22397/com.example.littlegrace.puppydex E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
06-19 20:51:54.883 22289-22398/com.example.littlegrace.puppydex E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
06-19 20:51:54.884 22289-22398/com.example.littlegrace.puppydex I/chatty: uid=10081(com.example.littlegrace.puppydex) hwuiTask2 identical 3 lines
06-19 20:51:54.885 22289-22398/com.example.littlegrace.puppydex E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE)
06-19 20:55:20.245 22289-22298/com.example.littlegrace.puppydex I/zygote: Do partial code cache collection, code=30KB, data=29KB
06-19 20:55:20.248 22289-22298/com.example.littlegrace.puppydex I/zygote: After code cache collection, code=30KB, data=29KB
Increasing code cache capacity to 128KB
06-19 20:55:20.904 22289-22298/com.example.littlegrace.puppydex I/zygote: Do partial code cache collection, code=53KB, data=58KB
06-19 20:55:20.911 22289-22298/com.example.littlegrace.puppydex I/zygote: After code cache collection, code=53KB, data=58KB
Increasing code cache capacity to 256KB
06-19 20:55:20.916 22289-22298/com.example.littlegrace.puppydex I/zygote: JIT allocated 56KB for compiled code of void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
06-19 20:55:20.984 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:22.531 22289-22298/com.example.littlegrace.puppydex I/zygote: Do full code cache collection, code=121KB, data=100KB
After code cache collection, code=121KB, data=81KB
06-19 20:55:22.731 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:22.776 22289-22316/com.example.littlegrace.puppydex I/chatty: uid=10081(com.example.littlegrace.puppydex) RenderThread identical 1 line
06-19 20:55:22.929 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:26.223 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:27.105 22289-22298/com.example.littlegrace.puppydex I/zygote: Do partial code cache collection, code=123KB, data=78KB
06-19 20:55:27.113 22289-22298/com.example.littlegrace.puppydex I/zygote: After code cache collection, code=123KB, data=78KB
Increasing code cache capacity to 512KB
06-19 20:55:31.244 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:31.288 22289-22316/com.example.littlegrace.puppydex I/chatty: uid=10081(com.example.littlegrace.puppydex) RenderThread identical 1 line
06-19 20:55:31.415 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:31.450 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:31.490 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:32.670 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:34.093 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:35.808 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:35.847 22289-22316/com.example.littlegrace.puppydex I/chatty: uid=10081(com.example.littlegrace.puppydex) RenderThread identical 1 line
06-19 20:55:35.891 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:35.942 22289-22316/com.example.littlegrace.puppydex D/OpenGLRenderer: endAllActiveAnimators on 0xcc55c100 (ListView) with handle 0xcb0a1760
06-19 20:55:35.967 22289-22298/com.example.littlegrace.puppydex I/zygote: Do full code cache collection, code=248KB, data=173KB
06-19 20:55:35.973 22289-22298/com.example.littlegrace.puppydex I/zygote: After code cache collection, code=248KB, data=143KB
06-19 20:55:37.841 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:39.358 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:39.395 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:39.557 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:39.597 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:39.614 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:40.834 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:43.836 22289-22298/com.example.littlegrace.puppydex I/zygote: Do partial code cache collection, code=248KB, data=151KB
06-19 20:55:43.837 22289-22298/com.example.littlegrace.puppydex I/zygote: After code cache collection, code=248KB, data=151KB
06-19 20:55:43.838 22289-22298/com.example.littlegrace.puppydex I/zygote: Increasing code cache capacity to 1024KB
06-19 20:55:43.991 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:55:44.700 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:56:38.076 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:56:39.322 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:56:39.466 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:56:39.515 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:56:42.759 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:59:09.925 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:59:09.971 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:59:10.000 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:59:10.044 22289-22316/com.example.littlegrace.puppydex I/chatty: uid=10081(com.example.littlegrace.puppydex) RenderThread identical 1 line
06-19 20:59:10.059 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:59:11.364 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 20:59:16.278 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 21:06:10.154 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 21:06:12.067 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 21:06:15.149 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 21:06:15.189 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 21:06:15.223 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 21:06:15.260 22289-22316/com.example.littlegrace.puppydex I/chatty: uid=10081(com.example.littlegrace.puppydex) RenderThread identical 1 line
06-19 21:06:15.293 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
06-19 21:06:16.597 22289-22316/com.example.littlegrace.puppydex D/EGL_emulation: eglMakeCurrent: 0xe5085180: ver 3 1 (tinfo 0xe5083320)
我的主课:
public class ToyGroup extends AppCompatActivity {
ListView tListView;
int[] images = {
R.drawable.fox,
R.drawable.havan,
R.drawable.malt,
R.drawable.papi,
R.drawable.pom,
R.drawable.poodle,
R.drawable.pug,
R.drawable.shihtzu,
R.drawable.yorkie,
R.drawable.chi};
String[] breed = {
"Fox Terrier",
"Havanese",
"Maltese",
"Papillon",
"Pomeranian",
"Poodle",
"Pug",
"Shih Tzu",
"Yorkshire Terrier",
"Chihuahua"
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.toylist_view);
tListView = (ListView) findViewById(R.id.ToyList);
CustomAdapter customAdapter = new CustomAdapter();
tListView.setAdapter(customAdapter);
tListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String breeds = breed[position];
final int image = images[position];
String[] toydescription = getResources().getStringArray(R.array.toydescription);
final String toydespos = toydescription[position];
Intent intent = new Intent(getApplicationContext(),ToyDetails.class);
intent.putExtra("toydespos",toydespos);
startActivity(intent);
}
});
}
class CustomAdapter extends BaseAdapter{
@Override
public int getCount() {
return images.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = getLayoutInflater().inflate(R.layout.activity_toy_group, null);
ImageView tImageView = (ImageView) view.findViewById(R.id.thumbnail);
TextView tTextView = (TextView) view.findViewById(R.id.rowName);
tImageView.setImageResource(images[position]);
tTextView.setText(breed[position]);
return view;
}
}
}
细节类:
public class ToyDetails extends ToyGroup
{
String description;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.toy_detailactivity);
TextView toyDesc = (TextView) findViewById(R.id.toydesc);
Bundle extras = getIntent().getExtras();
if (extras != null)
{
description = extras.getString("toydescpos");
toyDesc.setText(description);
}
}
}
详情页布局 View :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="400dp" >
<TextView
android:id="@+id/toydesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="fill_horizontal"
android:text="TextView" />
</RelativeLayout>
</ScrollView>
数组资源页面(只是一个 fragment ,因为它太大了):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="toydescription">
<item>Outgoing Toy Fox Terriers have serious FOMO (fear of missing out):
whatever you're doing, they want to be along for the ride.
Literally, in some cases — this breed used to ride in the saddlebags of
hunters, who took them out to catch small prey.
They've also performed in circuses, impressing audiences with their
jumping skills and ability to walk a tightrope.
Sometimes, though, these feisty furballs just want to stay in with you
for movies and cuddles.
Toy Fox Terriers are sometimes called an “AmerToy” breed because — you
guessed it — this toy breed originated in the United States.
Those huge bat ears and naturally bobbed tail give the Toy Fox Terrier a
distinctive look.
</item>
</string-array>
<resources>
最佳答案
数组索引从零开始。当位置为零时,以下行的索引变为 -1:
String breeds = breed[position-1]; // breed[-1]
final int image = images[position-1]; // images[-1]
final String toydespos = toydescription[position-1]; //toydescription[-1]
抛出 ArrayIndexOutOfBoundsException
。删除 -1
或根据您的要求修改代码。
编辑:
使用以下更改:
在您的 CustomAdapter
中:
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
在您的 onItemClick
中:
String breeds = breed[position];
final int image = images[position];
final String toydespos = toydescription[position]
关于java - 如何使用基于 ListView 选择的字符串数组填充 Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50923241/
如何使用 SPListCollection.Add(String, String, String, String, Int32, String, SPListTemplate.QuickLaunchO
我刚刚开始使用 C++ 并且对 C# 有一些经验,所以我有一些一般的编程经验。然而,似乎我马上就被击落了。我试过在谷歌上寻找,以免浪费任何人的时间,但没有结果。 int main(int argc,
这个问题已经有答案了: In Java 8 how do I transform a Map to another Map using a lambda? (8 个回答) Convert a Map>
我正在使用 node + typescript 和集成的 swagger 进行 API 调用。我 Swagger 提出以下要求 http://localhost:3033/employees/sear
我是 C++ 容器模板的新手。我收集了一些记录。每条记录都有一个唯一的名称,以及一个字段/值对列表。将按名称访问记录。字段/值对的顺序很重要。因此我设计如下: typedef string
我需要这两种方法,但j2me没有,我找到了一个replaceall();但这是 replaceall(string,string,string); 第二个方法是SringBuffer但在j2me中它没
If string is an alias of String in the .net framework为什么会发生这种情况,我应该如何解释它: type JustAString = string
我有两个列表(或字符串):一个大,另一个小。 我想检查较大的(A)是否包含小的(B)。 我的期望如下: 案例 1. B 是 A 的子集 A = [1,2,3] B = [1,2] contains(A
我有一个似乎无法解决的小问题。 这里...我有一个像这样创建的输入... var input = $(''); 如果我这样做......一切都很好 $(this).append(input); 如果我
我有以下代码片段 string[] lines = objects.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.No
这可能真的很简单,但我已经坚持了一段时间了。 我正在尝试输出一个字符串,然后输出一个带有两位小数的 double ,后跟另一个字符串,这是我的代码。 System.out.printf("成本:%.2
以下是 Cloud Firestore 列表查询中的示例之一 citiesRef.where("state", ">=", "CA").where("state", "= 字符串,我们在Stack O
我正在尝试检查一个字符串是否包含在另一个字符串中。后面的代码非常简单。我怎样才能在 jquery 中做到这一点? function deleteRow(locName, locID) { if
这个问题在这里已经有了答案: How to implement big int in C++ (14 个答案) 关闭 9 年前。 我有 2 个字符串,都只包含数字。这些数字大于 uint64_t 的
我有一个带有自定义转换器的 Dozer 映射: com.xyz.Customer com.xyz.CustomerDAO customerName
这个问题在这里已经有了答案: How do I compare strings in Java? (23 个回答) 关闭 6 年前。 我想了解字符串池的工作原理以及一个字符串等于另一个字符串的规则是
我已阅读 this问题和其他一些问题。但它们与我的问题有些无关 对于 UILabel 如果你不指定 ? 或 ! 你会得到这样的错误: @IBOutlet property has non-option
这两种方法中哪一种在理论上更快,为什么? (指向字符串的指针必须是常量。) destination[count] 和 *destination++ 之间的确切区别是什么? destination[co
This question already has answers here: Closed 11 years ago. Possible Duplicates: Is String.Format a
我有一个Stream一个文件的,现在我想将相同的单词组合成 Map这很重要,这个词在 Stream 中出现的频率. 我知道我必须使用 collect(Collectors.groupingBy(..)
我是一名优秀的程序员,十分优秀!