我正在android studio中搜索一个简单的列表视图。我创建了这个类: Success.java
public class Success extends Activity {
protected String[] plates = {"AA 367 AM", "AA 367 AL","AA 367 AK"};
protected ListAdapter adapter;
private ListView myListView;
EditText inputSearch;
ArrayAdapter<String> myAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.success);
inputSearch = (EditText) findViewById (R.id.searchText);
myListView = (ListView) findViewById (R.id.list);
myAdapter = new ArrayAdapter<String>(this, R.layout.plates, R.id.plate_name, plates);
myListView.setAdapter(myAdapter);
myListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String item = ((TextView)view).getText().toString();
Intent intent = new Intent(Success.this,Info.class);
intent.putExtra("Plate",item);
startActivity(intent);
}
});
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
Success.this.myAdapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
}
}
和success.xml
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/searchButton"
android:text="Search"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_gravity="right" />
<EditText
android:id="@+id/searchText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbars="vertical"/>
</LinearLayout>
搜索有效但项目点击显示不幸的是,program2已停止 Info.java
public class Info extends Activity {
ImageView imageView2;
ImageView imageView3;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
imageView2=(ImageView)findViewById(R.id.imageView2);
imageView3=(ImageView)findViewById(R.id.imageView3);
TextView tv3 = (TextView) findViewById(R.id.intent3);
String plate = getIntent().getExtras().getString("Plate");
tv3.setText(""+getIntent().getExtras().getString("Plate"));
imageView2.setImageResource(R.drawable.car1);
imageView3.setImageResource(R.drawable.status1);
}
}
修改
07-18 10:34:08.343 164-165/? E/RSA﹕ clarence - socket_local_client error! 111
07-18 10:34:08.349 164-164/? D/ADB_SERVICES﹕ adb fdevent_process list (15) (22)
07-18 10:34:08.349 164-164/? D/ADB_SERVICES﹕ adb socket read list (22)
07-18 10:34:08.349 164-164/? D/ADB_SERVICES﹕ read_data=11265
07-18 10:34:08.349 164-164/? D/ADB_SERVICES﹕ max_read_time=0.000107 max_send_time=0.000073
07-18 10:34:08.499 10816-10816/com.Program2 I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x51ae9cf0) fps:1.99, dur:1003.59, max:505.02, min:498.57
07-18 10:34:08.500 133-468/? I/BufferQueue﹕ [com.Program2/com.Program2.Main](this:0x41d27a40,api:2) [queue] fps:1.99, dur:1003.56, max:504.90, min:498.66
07-18 10:34:08.505 133-173/? I/BufferQueue﹕ [com.Program2/com.Program2.Main](this:0x41d27a40,api:2) [release] fps:1.99, dur:1003.57, max:501.79, min:501.78
07-18 10:34:08.506 133-173/? I/SurfaceFlinger﹕ [SurfaceFlinger] fps:3.985810,dur:1003.56,max:351.11,min:150.66
07-18 10:34:08.791 510-574/? D/StateMachine﹕ handleMessage: E msg.what=131155
07-18 10:34:08.791 510-574/? D/StateMachine﹕ processMsg: ConnectedState
07-18 10:34:08.792 510-574/? D/WifiStateMachine﹕ ConnectedState{ what=131155 when=-4ms arg1=2 target=Handler (com.android.internal.util.StateMachine$SmHandler) {416e4d80} }
07-18 10:34:08.792 510-574/? D/StateMachine﹕ processMsg: L2ConnectedState
07-18 10:34:08.793 510-574/? D/WifiStateMachine﹕ L2ConnectedState{ what=131155 when=-5ms arg1=2 target=Handler (com.android.internal.util.StateMachine$SmHandler) {416e4d80} }
07-18 10:34:08.793 510-574/? D/WifiNative-wlan0﹕ doString: SIGNAL_POLL
07-18 10:34:08.793 510-574/? D/WifiCommon﹕ [wlan0] SET "SIGNAL_POLL"
07-18 10:34:08.794 719-719/? D/wpa_supplicant﹕ RX ctrl_iface - hexdump(len=11): 53 49 47 4e 41 4c 5f 50 4f 4c 4c
07-18 10:34:08.794 719-719/? D/wpa_supplicant﹕ wlan0: Control interface command 'SIGNAL_POLL'
07-18 10:34:08.816 719-719/? D/wpa_supplicant﹕ nl80211: survey data missing!
07-18 10:34:08.817 510-574/? I/WifiStateMachine﹕ fetchRssiAndLinkSpeedNative, newRssi:-58, newLinkSpeed:54
07-18 10:34:08.817 510-574/? D/StateMachine﹕ handleMessage: X
07-18 10:34:09.344 164-165/? E/RSA﹕ clarence - socket_local_client error! 111
07-18 10:34:09.345 670-670/? I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x52d9c570) fps:1.33, dur:1506.00, max:1003.20, min:502.79
07-18 10:34:09.346 133-357/? I/BufferQueue﹕ [StatusBar](this:0x41d0b948,api:1) [queue] fps:1.33, dur:1506.66, max:1003.91, min:502.75
07-18 10:34:09.352 164-164/? D/ADB_SERVICES﹕ adb local_socket_ready list (22)
07-18 10:34:09.358 133-173/? I/BufferQueue﹕ [StatusBar](this:0x41d0b948,api:1) [release] fps:1.33, dur:1505.35, max:1003.48, min:501.87
07-18 10:34:09.861 133-173/? I/SurfaceFlinger﹕ [SurfaceFlinger] fps:2.952940,dur:1354.58,max:501.69,min:133.93
07-18 10:34:09.987 10816-10816/com.Program2 I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x51ae9cf0) fps:2.02, dur:1487.80, max:501.54, min:485.06
07-18 10:34:09.988 133-133/? I/BufferQueue﹕ [com.Program2/com.Program2.Main](this:0x41d27a40,api:2) [queue] fps:2.02, dur:1487.84, max:501.43, min:485.05
07-18 10:34:09.994 133-173/? I/BufferQueue﹕ [com.Program2/com.Program2.Main](this:0x41d27a40,api:2) [release] fps:2.02, dur:1488.59, max:501.77, min:485.05
07-18 10:34:10.320 510-530/? V/Provider/Settings﹕ from settings cache , name = read_external_storage_enforced_default , value = null
07-18 10:34:10.322 134-10867/? D/dalvikvm﹕ threadid=2: exiting
07-18 10:34:10.322 134-10867/? D/dalvikvm﹕ threadid=2: bye!
07-18 10:34:10.323 134-10875/? D/dalvikvm﹕ threadid=3: exiting
07-18 10:34:10.323 134-10875/? D/dalvikvm﹕ threadid=3: bye!
07-18 10:34:10.325 134-10876/? D/dalvikvm﹕ threadid=4: exiting
07-18 10:34:10.325 134-10876/? D/dalvikvm﹕ threadid=4: bye!
07-18 10:34:10.326 134-134/? D/dalvikvm﹕ pre gc
07-18 10:34:10.326 134-134/? D/dalvikvm﹕ Zygote::ForkAndSpecialize +
07-18 10:34:10.337 134-134/? D/dalvikvm﹕ Zygote::ForkAndSpecialize : 10880
07-18 10:34:10.338 134-134/? D/dalvikvm﹕ create interp thread : stack size=32KB
07-18 10:34:10.339 10880-10880/? D/dalvikvm﹕ Zygote::ForkAndSpecialize : 0
07-18 10:34:10.340 134-134/? D/dalvikvm﹕ create new thread
07-18 10:34:10.343 162-162/? I/sdcard﹕ [0] SETATTR fh=0 valid=1 @ 40a36070 (0)
07-18 10:34:10.343 134-134/? D/dalvikvm﹕ new thread created
07-18 10:34:10.343 134-134/? D/dalvikvm﹕ update thread list
07-18 10:34:10.344 164-165/? E/RSA﹕ clarence - socket_local_client error! 111
07-18 10:34:10.349 670-670/? I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x52d9c570) fps:1.99, dur:1004.20, max:503.14, min:501.06
07-18 10:34:10.350 133-468/? I/BufferQueue﹕ [StatusBar](this:0x41d0b948,api:1) [queue] fps:1.99, dur:1004.12, max:503.78, min:500.34
07-18 10:34:10.352 10880-10880/? E/cutils﹕ to chown(/mnt/shell/emulated/0, 0, 0)
07-18 10:34:10.353 162-169/? I/sdcard﹕ [1] SETATTR fh=0 valid=6 @ 40a36070 (0)
07-18 10:34:10.354 162-162/? I/sdcard﹕ [0] SETATTR fh=0 valid=1 @ 40a36148 (obb)
07-18 10:34:10.355 10880-10880/? E/cutils﹕ to chown(/mnt/shell/emulated/obb, 0, 0)
07-18 10:34:10.356 162-162/? I/sdcard﹕ [0] SETATTR fh=0 valid=6 @ 40a36148 (obb)
07-18 10:34:10.357 162-162/? I/sdcard﹕ [0] SETATTR fh=0 valid=1 @ 40a36190 (Android)
07-18 10:34:10.358 10880-10880/? E/cutils﹕ to chown(/storage/emulated/0/Android, 0, 0)
07-18 10:34:10.359 162-169/? I/sdcard﹕ [1] SETATTR fh=0 valid=6 @ 40a36190 (Android)
07-18 10:34:10.360 162-169/? I/sdcard﹕ [1] SETATTR fh=0 valid=1 @ 40a361d8 (obb)
07-18 10:34:10.360 10880-10880/? E/cutils﹕ to chown(/storage/emulated/0/Android/obb, 0, 0)
07-18 10:34:10.362 133-173/? I/BufferQueue﹕ [StatusBar](this:0x41d0b948,api:1) [release] fps:1.99, dur:1003.61, max:501.82, min:501.79
07-18 10:34:10.363 162-162/? I/sdcard﹕ [0] SETATTR fh=0 valid=6 @ 40a361d8 (obb)
07-18 10:34:10.365 134-10881/? D/dalvikvm﹕ threadid=2: interp stack at 0x4f3c6000
07-18 10:34:10.366 10880-10880/? D/dalvikvm﹕ zygote get new systemTid : 10880
07-18 10:34:10.367 10880-10882/? D/dalvikvm﹕ threadid=2: interp stack at 0x4f4c6000
07-18 10:34:10.368 134-10881/? D/dalvikvm﹕ threadid=2: created from interp
07-18 10:34:10.368 134-134/? D/dalvikvm﹕ start new thread
07-18 10:34:10.368 134-134/? D/dalvikvm﹕ create interp thread : stack size=32KB
07-18 10:34:10.368 134-134/? D/dalvikvm﹕ create new thread
07-18 10:34:10.368 134-134/? D/dalvikvm﹕ new thread created
07-18 10:34:10.368 134-134/? D/dalvikvm﹕ update thread list
07-18 10:34:10.369 134-10881/? D/dalvikvm﹕ threadid=2: notify debugger
07-18 10:34:10.369 134-10881/? D/dalvikvm﹕ threadid=2 (ReferenceQueueDaemon): calling run()
07-18 10:34:10.370 10880-10884/? D/dalvikvm﹕ threadid=3: interp stack at 0x4f5ce000
07-18 10:34:10.371 10880-10884/? D/dalvikvm﹕ Elevating priority from 0 to -8
07-18 10:34:10.371 10880-10885/? D/dalvikvm﹕ threadid=4: interp stack at 0x4f6d6000
07-18 10:34:10.371 10880-10880/? D/dalvikvm﹕ zygote get thread init done
07-18 10:34:10.372 10880-10880/? D/dalvikvm﹕ create interp thread : stack size=32KB
07-18 10:34:10.372 10880-10880/? D/dalvikvm﹕ create new thread
07-18 10:34:10.372 10880-10880/? D/dalvikvm﹕ new thread created
07-18 10:34:10.373 134-10883/? D/dalvikvm﹕ threadid=3: interp stack at 0x4f4ce000
07-18 10:34:10.373 134-10883/? D/dalvikvm﹕ threadid=3: created from interp
07-18 10:34:10.373 10880-10880/? D/dalvikvm﹕ update thread list
07-18 10:34:10.373 10880-10886/? D/dalvikvm﹕ threadid=5: interp stack at 0x51af4000
07-18 10:34:10.373 134-134/? D/dalvikvm﹕ start new thread
07-18 10:34:10.374 134-134/? D/dalvikvm﹕ create interp thread : stack size=32KB
07-18 10:34:10.374 134-134/? D/dalvikvm﹕ create new thread
07-18 10:34:10.374 134-134/? D/dalvikvm﹕ new thread created
07-18 10:34:10.374 134-134/? D/dalvikvm﹕ update thread list
07-18 10:34:10.375 134-10883/? D/dalvikvm﹕ threadid=3: notify debugger
07-18 10:34:10.375 134-10883/? D/dalvikvm﹕ threadid=3 (FinalizerDaemon): calling run()
07-18 10:34:10.375 10880-10886/? D/dalvikvm﹕ threadid=5: created from interp
07-18 10:34:10.375 10880-10880/? D/dalvikvm﹕ start new thread
07-18 10:34:10.376 10880-10880/? D/dalvikvm﹕ create interp thread : stack size=32KB
07-18 10:34:10.376 10880-10880/? D/dalvikvm﹕ create new thread
07-18 10:34:10.376 10880-10880/? D/dalvikvm﹕ new thread created
07-18 10:34:10.376 10880-10880/? D/dalvikvm﹕ update thread list
07-18 10:34:10.376 10880-10886/? D/dalvikvm﹕ threadid=5: notify debugger
07-18 10:34:10.376 10880-10886/? D/dalvikvm﹕ threadid=5 (ReferenceQueueDaemon): calling run()
07-18 10:34:10.377 10880-10888/? D/dalvikvm﹕ threadid=6: interp stack at 0x51bfc000
07-18 10:34:10.377 10880-10888/? D/dalvikvm﹕ threadid=6: created from interp
07-18 10:34:10.377 10880-10880/? D/dalvikvm﹕ start new thread
07-18 10:34:10.378 10880-10880/? D/dalvikvm﹕ create interp thread : stack size=32KB
07-18 10:34:10.379 10880-10880/? D/dalvikvm﹕ create new thread
07-18 10:34:10.379 10880-10880/? D/dalvikvm﹕ new thread created
07-18 10:34:10.379 10880-10880/? D/dalvikvm﹕ update thread list
07-18 10:34:10.379 10880-10888/? D/dalvikvm﹕ threadid=6: notify debugger
07-18 10:34:10.379 10880-10888/? D/dalvikvm﹕ threadid=6 (FinalizerDaemon): calling run()
07-18 10:34:10.380 10880-10889/? D/dalvikvm﹕ threadid=7: interp stack at 0x51d04000
07-18 10:34:10.380 10880-10889/? D/dalvikvm﹕ threadid=7: created from interp
07-18 10:34:10.380 10880-10880/? D/dalvikvm﹕ start new thread
07-18 10:34:10.381 134-10887/? D/dalvikvm﹕ threadid=4: interp stack at 0x4f5d6000
07-18 10:34:10.381 134-10887/? D/dalvikvm﹕ threadid=4: created from interp
07-18 10:34:10.382 134-134/? D/dalvikvm﹕ start new thread
07-18 10:34:10.392 134-10887/? D/dalvikvm﹕ threadid=4: notify debugger
07-18 10:34:10.392 134-10887/? D/dalvikvm﹕ threadid=4 (FinalizerWatchdogDaemon): calling run()
07-18 10:34:10.393 510-530/? I/ActivityManager﹕ Start proc com.feelingtouch.dipan.slggameglobal for service com.feelingtouch.dipan.slggameglobal/com.amazonaws.androidtest.MessageReceivingService: pid=10880 uid=10099 gids={50099, 3003, 1028, 1015}
07-18 10:34:10.399 10880-10889/? D/dalvikvm﹕ threadid=7: notify debugger
07-18 10:34:10.399 10880-10889/? D/dalvikvm﹕ threadid=7 (FinalizerWatchdogDaemon): calling run()
07-18 10:34:10.399 10843-10856/? I/ATCIJ﹕ Couldn't find 'atci-serv-fw' socket; retrying after timeout
07-18 10:34:10.399 10880-10890/? D/dalvikvm﹕ threadid=8: interp stack at 0x5210a000
07-18 10:34:10.413 10880-10891/? D/dalvikvm﹕ threadid=9: interp stack at 0x52212000
07-18 10:34:10.415 510-1141/? V/ActivityManager﹕ Binding process pid 10880 to record ProcessRecord{417db9c8 10880:com.feelingtouch.dipan.slggameglobal/u0a10099}
07-18 10:34:10.415 510-1141/? V/ActivityManager﹕ New death recipient com.android.server.am.ActivityManagerService$AppDeathRecipient@414e95b8 for thread android.os.BinderProxy@41aa2d30
07-18 10:34:10.416 510-1141/? V/ActivityManager﹕ New app record ProcessRecord{417db9c8 10880:com.feelingtouch.dipan.slggameglobal/u0a10099} thread=android.os.BinderProxy@41aa2d30 pid=10880
07-18 10:34:10.419 134-134/? D/dalvikvm﹕ GC_EXPLICIT freed 42K (1048), 8% free 2558K/2752K, paused 2ms+2ms, total 37ms
07-18 10:34:10.447 10880-10880/? D/dalvikvm﹕ open_cached_dex_file : /data/app/com.feelingtouch.dipan.slggameglobal-1.apk /data/dalvik-cache/data@app@com.feelingtouch.dipan.slggameglobal-1.apk@classes.dex
07-18 10:34:10.454 10880-10880/? D/dalvikvm﹕ create interp thread : stack size=32KB
07-18 10:34:10.454 10880-10880/? D/dalvikvm﹕ create new thread
07-18 10:34:10.454 10880-10880/? D/dalvikvm﹕ new thread created
07-18 10:34:10.455 10880-10880/? D/dalvikvm﹕ update thread list
07-18 10:34:10.455 134-134/? D/dalvikvm﹕ GC_EXPLICIT freed <1K (2), 8% free 2558K/2752K, paused 2ms+1ms, total 35ms
07-18 10:34:10.455 10880-10892/? D/dalvikvm﹕ threadid=10: interp stack at 0x52855000
07-18 10:34:10.456 10880-10892/? D/dalvikvm﹕ threadid=10: created from interp
07-18 10:34:10.456 10880-10880/? D/dalvikvm﹕ start new thread
07-18 10:34:10.457 10880-10880/? D/dalvikvm﹕ create interp thread : stack size=32KB
07-18 10:34:10.458 10880-10880/? D/dalvikvm﹕ create new thread
07-18 10:34:10.459 10880-10880/? D/dalvikvm﹕ new thread created
07-18 10:34:10.459 10880-10880/? D/dalvikvm﹕ update thread list
07-18 10:34:10.459 10880-10892/? D/dalvikvm﹕ threadid=10: notify debugger
07-18 10:34:10.459 10880-10892/? D/dalvikvm﹕ threadid=10 (SharedPreferencesImpl-load): calling run()
07-18 10:34:10.465 10880-10893/? D/dalvikvm﹕ threadid=11: interp stack at 0x5295d000
07-18 10:34:10.465 10880-10893/? D/dalvikvm﹕ threadid=11: created from interp
07-18 10:34:10.465 10880-10880/? D/dalvikvm﹕ start new thread
07-18 10:34:10.469 10880-10892/? D/dalvikvm﹕ threadid=10: exiting
07-18 10:34:10.469 10880-10892/? D/dalvikvm﹕ threadid=10: bye!
07-18 10:34:10.470 10880-10893/? D/dalvikvm﹕ threadid=11: notify debugger
07-18 10:34:10.470 10880-10893/? D/dalvikvm﹕ threadid=11 (SharedPreferencesImpl-load): calling run()
07-18 10:34:10.470 10880-10893/? D/dalvikvm﹕ threadid=11: exiting
07-18 10:34:10.470 10880-10893/? D/dalvikvm﹕ threadid=11: bye!
07-18 10:34:10.491 134-134/? D/dalvikvm﹕ GC_EXPLICIT freed <1K (5), 8% free 2558K/2752K, paused 4ms+2ms, total 35ms
07-18 10:34:10.515 510-736/? V/ActivityManager﹕ getTasks: max=1, flags=0, receiver=null
07-18 10:34:10.515 510-736/? V/ActivityManager﹕ com.Program2/.Main: task=TaskRecord{41e8e048 #18 A com.Program2 U 0}
07-18 10:34:10.516 510-736/? V/ActivityManager﹕ We have pending thumbnails: null
07-18 10:34:10.865 133-173/? I/SurfaceFlinger﹕ [SurfaceFlinger] fps:3.985524,dur:1003.63,max:368.79,min:132.94
07-18 10:34:10.991 10816-10816/com.Program2 I/SurfaceTextureClient﹕ [STC::queueBuffer] (this:0x51ae9cf0) fps:1.99, dur:1003.49, max:503.53, min:499.96
07-18 10:34:10.991 133-1738/? I/BufferQueue﹕ [com.Program2/com.Program2.Main](this:0x41d27a40,api:2) [queue] fps:1.99, dur:1003.50, max:503.46, min:500.04
07-18 10:34:10.997 133-173/? I/BufferQueue﹕ [com.Program2/com.Program2.Main](this:0x41d27a40,api:2) [release] fps:1.99, dur:1003.55, max:502.00, min:501.55
答案 0 :(得分:0)
我认为问题是当listItemClicked时,你将视图转换为TextView,这是错误的。您应该使用String item = ((TextView)view.findViewById(R.id.yourTextViewID)).getText().toString()