0

ユーザーがリストビューのアイテムをクリックすると、アラートダイアログボックスが表示され、予約またはキャンセルのオプションが表示されるように、ページを設定できました。彼らが本をクリックすると、別の画面に移動します。必要なのは、次の画面で選択したアイテムを表示することです。私はほとんどそれを持っていますが、どこがうまくいかないのかわかりません。私が望んでいたのは、誰かがこれを行うための最良の方法を見つけるのを手伝ってくれるかどうかです。

現在の私のコードは-

        lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> a, View v, final int position, long id)
       {   
            final int selectedPosition = position;
            AlertDialog.Builder adb=new AlertDialog.Builder(ListTaxi.this); 
             adb.setTitle("Taxi Booking");
             adb.setMessage("You have chosen = "+lv.getItemAtPosition(position)); 
             adb.setPositiveButton("Book", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     Intent intent = new Intent(getApplicationContext(), Booking.class);
                     intent.putExtra("booking",  taxi[selectedPosition]);
                     startActivity(intent);
                 }
             });
             adb.setNegativeButton("Cancel", null); 
             adb.show(); 
         }
     });

そしてbooking.javaには次のようなものがあります。

public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState); setContentView(R.layout.booking); TextView tv_taxi =(TextView)findViewById(R.id.tvtaxi); //tv_taxi.setText(taxi);

        Intent intent = getIntent();
        String booking = "";
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                booking = extras.getString("booking");   

            }


            }

        }

元の記事は-Android-alertdialogボタンがクリックされたときにビューを変更する

みんな、ありがとう

4

1 に答える 1

1

TextViewから取得した値になるようにテキストを設定する必要があります。Bundle

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.booking);
    TextView tv_taxi = (TextView) findViewById(R.id.tvtaxi);
    Intent intent = getIntent();
    String booking = "";
    if (intent != null) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            booking = extras.getString("booking");
            tv_taxi.setText(booking);
        }
    }
}
于 2011-01-03T17:40:46.990 に答える