我想在 my 中單擊某個(gè)項(xiàng)目時(shí)在 a 中顯示Selecteditemposition(a 中單擊的項(xiàng)目數(shù)Listview),但此事件中的任何方法都崩潰了。ToastListview這是崩潰報(bào)告:2019-06-27 20:54:02.681 13006-13015/? E/ample.basicipt: Failed to send DDMS packet REAQ to debugger (-1 of 20): Broken pipe2019-06-27 20:54:17.470 13006-13006/com.example.basiciptv E/ample.basicipt: No package ID ff found for ID 0xffffffff.2019-06-27 20:54:17.472 13006-13006/com.example.basiciptv E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.basiciptv, PID: 13006 android.content.res.Resources$NotFoundException: String resource ID #0xffffffff at android.content.res.Resources.getText(Resources.java:348) at android.widget.Toast.makeText(Toast.java:307) at com.example.basiciptv.MainActivity$4.onItemClick(MainActivity.java:336) at android.widget.AdapterView.performItemClick(AdapterView.java:318) at android.widget.AbsListView.performItemClick(AbsListView.java:1192) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3169) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6692) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)這是代碼:list.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { boolean co = true; int lineNumber = listview.getSelectedItemPosition(); Toast.makeText(MainActivity.this, lineNumber, Toast.LENGTH_SHORT).show(); }});我究竟做錯(cuò)了什么?
2 回答

ITMISS
TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊
lineNumber
是一個(gè)整數(shù),所以你正在使用這個(gè)重載makeText()
:
makeText(Context context, int resId, int duration)
它需要一個(gè)整數(shù)字符串資源 id,因此lineNumber
被認(rèn)為是一個(gè)字符串資源 id,當(dāng)然不是,所以它找不到。
相反,您應(yīng)該做的是轉(zhuǎn)換lineNumber
為字符串并使用以下重載makeText()
:
makeText(Context context, CharSequence text, int duration)
所以這樣做:
Toast.makeText(MainActivity.this, String.valueOf(lineNumber), Toast.LENGTH_SHORT).show();

肥皂起泡泡
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊
所以 linenumber 已經(jīng)作為位置返回 onclick 方法。
Toast.maketext(getApplicationContext,position.toString(), Toast.LENGHT_LONG).show();
添加回答
舉報(bào)
0/150
提交
取消