0

私はAndroid開発の初心者です。を使用して別の画面に移動する方法を教えてくださいonListItemClick。に 200 個のアイテムがありListViewます。からアイテムをクリックするListViewと、クリックしたアイテムの詳細を表示する別の画面に移動する必要があります。

4

2 に答える 2

0

データベースからアクターのリストと詳細を取得していると仮定しています。同じウォークスルーを使用して、アプリで選択したレシピのレシピの詳細を表示しました。

    public class ActorList extends Activity {

       ListView myActorList=null;

public final static String selectedActor_ID="will Keep Actor ID";

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_actor_list);     

        //initialize controls

            myActorList.setAdapter(adapter);

            myActorList.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View v,
                        int position, long id) {
                    // TODO Auto-generated method stub


                    Intent i= new Intent(ActorList.this,ActorDetail.class);
                    // you have to pass the actor id to next activity
                    // you can get this actor id from argument of type "long"
                    i.putExtra(selectedActor_ID, String.valueOf(id));
                    startActivity(i);

                }           

            });

    }



}


//Other Activity To show Detail..

//get the ID of Selected Actor on other activity say "ActorDetail"

public class ActorDetail extends Activity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_actor_detail);

        ActorID=getIntent().getStringExtra(ActorList.selectedActor_ID);
// now as you have the id here for that particular actor
//fetch the detail of that selected actor thru id and bind it to your layout.       


    }



}       

このように、マニフェストファイルに他のアクティビティを登録する必要があります

<activity 
            android:name=".otherscreenActivity" 

        </activity>
于 2013-04-01T09:05:22.353 に答える
0

あなたが望むものを得るために、あなたはこのようなことをすることができます...

1>値を配置できる特定のコントロールを備えた別のアクティビティを作成します...

2>リストビューの itemclick() で... a>インテントを作成し、新しいアクティビティに渡す値を設定します b>このインテントで新しいアクティビティを開始します。

3>新しいアクティビティの oncreate() で a>インテントから値を取得する b>値を使用してコントロールに入力する...

于 2013-04-02T07:14:11.193 に答える