0
我有一個字符串數組,並且有一個名爲ship1的對象,它位於onItemClickListener中的if語句中。我想要一個對象值(addSpend)顯示在數組中的一個字符串中,但由於某種原因字符串數組無法識別或查看ship1。我如何解決這個問題? (我想旁邊顯示的「遊俠船」附加支出值)HangarActivity線28字符串數組不能識別對象的值和對象本身
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hangar);
String[] ship = {"Scout Ship", "Ranger Ship" , "Gun Ship MK.1",
"Conquerer Ship", "Gun Ship MK.2", "Tank Ship",
"Battle Ship MK.1", "Titan Ship", "Battle Ship MK.2",
"Colossal Titan Ship"};
ListView hangarList = (ListView) findViewById(R.id.hangarList);
ListAdapter adapter = new HangarAdapter(this, ship);
hangarList.setAdapter(adapter);
hangarList.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick (AdapterView <?> adapterView, View view,int position, long l){
Intent sendListEvents = new Intent();
if (position == 0) {
Ship ship1 = new Ship();
ship1.setAddAmount(50);
ship1.setAddTime(5000);
ship1.setAddSpend(1000);
ship1.shipAdd();
}
你的二傳手在哪裏? – 2014-09-23 19:02:16
好心發佈錯誤消息,使調試變得容易。 – User27854 2014-09-23 19:02:39
setContentView(R.layout.hangar)'<==這裏的半列 – Kiloreux 2014-09-23 19:03:33