2011-11-08 72 views
0

我有一个ListView,我想在弹出窗口中显示选中的列表内容,当我在视图中点击它时。我怎样才能做到这一点?如何膨胀膨胀同一班级的两种布局?

这里是我的代码:

public class EventbyDate extends ListActivity { 
    Context cont; 
    private Runnable DateEventListThread; 
    public String DateEventListThreadResponse; 
    private ProgressDialog m_ProgDialog = null; 
    public DateEventListAdapter DateEventList_adapter; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.eventsbydate); 
     GetDateEventList(); 
     this.DateEventList_adapter = new DateEventListAdapter(this,R.layout.eventsbydate_list, 
     RoamMeo_Config.DateEventList); 
     setListAdapter(this.DateEventList_adapter); 
    } 
    @Override 
    public void onPause() { 
     super.onPause(); 
     this.finish(); 
    } 
    void GetDateEventList() { 
     m_ProgDialog = ProgressDialog.show(EventbyDate.this, " Please wait", 
     "Collecting Data..", true); 
     DateEventListThread = new Runnable() { 
      @Override 
      public void run() { 
       DateEventListThread = null; 
       try { 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
       runOnUiThread(returnResponse); 
      } 
     }; 
     Thread thread = new Thread(null, DateEventListThread, "DateEventListThread"); 
     thread.start(); 
    } 
    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 
     super.onListItemClick(l, v, position, id); 
     LayoutInflater inflater = (LayoutInflater) EventbyDate. 
     this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup,null,  
     false),300,400,true); 

     pw.showAtLocation(findViewById(R.id.txt_start_date), 

     Gravity.CENTER, 0,0); 


    } 

    private Runnable returnResponse = new Runnable() { 
     @Override 
     public void run() {    
      try { 
       if (DateEventListThreadResponse != null&& 

         DateEventListThreadResponse.length() > 0) { 
        boolean check = 
        XMLParsing.EventDate_List_Response(DateEventListThreadResponse); 
        if(check) { 


         DateEventList_adapter.notifyDataSetChanged();      
        } else { 
         Toast msg = 

         Toast.makeText(EventbyDate.this,"No list... ",Toast.LENGTH_LONG); 
         msg.setGravity(Gravity.CENTER, 

         msg.getXOffset()/2,msg.getYOffset()/2); 
         msg.show(); 
        } 
       } 
       if (m_ProgDialog != null) 
       m_ProgDialog.dismiss(); 
       m_ProgDialog = null; 
      } catch (Exception e) { 
       if (m_ProgDialog != null) 
       m_ProgDialog.dismiss(); 
       m_ProgDialog = null; 
      }   
     } 
    }; 

    class DateEventListAdapter extends ArrayAdapter<SaveDateEventList> { 
     ArrayList<SaveDateEventList> items; 
     public DateEventListAdapter(Context context, int 

     textViewResourceId, 
     ArrayList<SaveDateEventList> items) { 
      super(context, textViewResourceId, items); 
      this.items = items; 
     } 
     @Override 
     public View getView(int position, View convertView, ViewGroup 

     parent) { 
      View v = convertView; 
      final SaveDateEventList d = items.get(position); 
      if (v == null) { 
       LayoutInflater vi = (LayoutInflater) 

       getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       v = vi.inflate(R.layout.eventsbydate_list, null); 
      } 
      if (!items.isEmpty()) { 
       if (d != null) { 
        TextView start_date = (TextView) 

        v.findViewById(R.id.txt_start_date); 
        start_date.setText(d.ev_start_date); 

        TextView start_time = (TextView) 

        v.findViewById(R.id.txt_start_time); 
        start_time.setText(d.ev_start_time); 

        TextView poptext = (TextView) 

        v.findViewById(R.id.poptext); 
        poptext.setText(d.ev_start_time); 
       } 
      } 
      return v; 
     } 
    } 
} 

回答

0

你可以做这样的事情,protected void onListItemClick(ListView l, View v, int position, long id) {YourObject o = l.getItemAtPosition(position);}。之后,您必须通过此获取的对象设置您需要在弹出屏幕中显示的内容。

+0

但弹出窗口itslf显示在该列表项单击。如何将数据设置到该弹出窗口?这是我的qn! '@Override protected void onListItemClick(ListView l,View v,int position,long id){ \t \t \t super.onListItemClick(l,v,position,id); \t \t \t \t \t \t LayoutInflater充气=(LayoutInflater)EventbyDate.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup,null,false),300,400,true); \t pw.showAtLocation(findViewById(R.id.txt_start_date),Gravity.CENTER,0,0);}' – Froyo