0

リストビューがあり、ユーザーが項目を選択すると、データベース ( sqlite ) のデータと比較される新しいアクティビティが開き、データが取得されます。選択した項目の位置しか渡せないのですが、文字列自体は渡したいです。

最初のアクティビティのコード:

  list.setAdapter(adapter);  
       list.setOnItemClickListener(new OnItemClickListener() {   
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) {      

                Intent myIntent = new Intent(view.getContext(), ShowWhereToGo.class); 
                myIntent.putExtra("id", position);
                startActivityForResult(myIntent, 0); // display SubView.class               }
            }

            @SuppressWarnings("unused")
            public void onItemClick1(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub

            }});

2 番目のアクティビティのコード:

 Bundle extras = getIntent().getExtras();
     if (extras != null) {
         String temp = extras.getString("id");

      Toast.makeText(getApplicationContext(),
                    "Position :"+temp , Toast.LENGTH_LONG)
                .show();
     }
4

2 に答える 2

3

Listview の ItemClick で

  public void onItemClick(AdapterView<?> parent, View view,int position, long id)   {      
      Intent myIntent = new Intent(view.getContext(), ShowWhereToGo.class); 
      myIntent.putExtra("item", adapter.getItem(position));
      myIntent.putExtra("id", position);
      startActivityForResult(myIntent, 0); // display SubView.class               }
  }

回収中

     String item = getIntent().getExtras().getString("item");
于 2013-10-26T10:02:18.757 に答える
1

以下を使用してください

 String value =(String) parent.getItemAtPosition(position);
 myIntent.putExtra("value", value);

削除するonItemClick1

于 2013-10-26T10:01:26.433 に答える