开发者

how can i get my alertdialog to display listview info?

my alertdialog wont display the textview from my listview. when i click on the listview it only displays the first list of the list view string. could someone please help me!

package com.example.taxime;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class FindTaxi extends ListActivity {
 @Override
  public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

   final String[] number = getResources().getStringArray(R.array.number);
   setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,number));

   final String[] taxi = getResources().getStringArray(R.array.taxi);
   setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, taxi));

   ListView lv = getListView();
   lv.setTextFilterEnabled(true);

   lv.setOnItemClickListener(new OnItemClickListener() 开发者_如何学JAVA{
     public void onItemClick(AdapterView<?> parent, View view,
         int position, long id) {

      AlertDialog.Builder adb=new AlertDialog.Builder(FindTaxi.this);

       int selectedPosition = 0;
       adb.setTitle(""+taxi[selectedPosition]);
       adb.setMessage("Phone Number: "+number[selectedPosition]);
       adb.setPositiveButton(TELEPHONY_SERVICE, null);       
       adb.setNegativeButton("Cancel", null);
       adb.show();

     }
   });
 }
}


(Better late than never, right?)

Instead of this:

       int selectedPosition = 0;
       adb.setTitle(""+taxi[selectedPosition]);
       adb.setMessage("Phone Number: "+number[selectedPosition]);
Make use of the int position parameter the onItemClick method receives. So, the three lines of code above might then become:
       int selectedPosition = position;
       adb.setTitle(""+taxi[selectedPosition]);
       adb.setMessage("Phone Number: "+number[selectedPosition]);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜