2010-12-23 13 views
1

Ich habe ein Hauptlayout, das keine Listenansicht hat, und auf Knopf Ich bin ein Pop-up-Fenster in diesem Pop-up-Fenster Ich habe eine Schaltfläche, nämlich Ereignis hinzufügen, wenn ich auf Ereignis hinzufügen Schaltfläche vil raise klicken ein weiteres Pop-up in dem es eine Listenansicht gibt. Ich möchte einige String-Array-Werte im Popup-Layout auflisten, aber wenn ich List im Popup-Layout deklariere, bekomme ich Fehler, aber wenn ich Listen-ID im Hauptlayout erstelle, bekomme ich Listenansicht im Hauptlayout, aber was ich will ist, dass ich möchte meine Liste im Popup-Layout anzeigen ... HIER ist mein Code ... PLACE Ich bekomme Fehler = ---------------------- ----------------------------------------Android-Listenansicht

setListAdapter(new ArrayAdapter<String>(Main.this, 
    android.R.layout.simple_list_item_1, mStrings)); 
getListView().setTextFilterEnabled(true); 

public class Main extends ListActivity implements OnClickListener 
{ 

// String name, id_val, title_val, date_val, desc_val, link_val, linkname_val,name_val; 
// String[] PROJECTION = { BaseColumns._ID, Constants.TITLE}; 
// String[] FROM = { Constants.TITLE}; 
// int[] TO = { R.id.event_txt}; 
// 

    private String[] mStrings = { 
      "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", 
      "Bresse Bleu", "Brick", "Brie", "Brie de Meaux", "Brie de Melun", "Brillat-Savarin", 
      "Brin", "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)", 
      "Briquette de Brebis", "Briquette du Forez", "Broccio", "Broccio Demi-Affine", 
      "Brousse du Rove", "Bruder Basil", "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza", 
      "Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase", "Button (Innes)", 
      "Buxton Blue", "Cabecou", "Caboc", "Cabrales", "Cachaille", "Caciocavallo", "Caciotta", 
      "Caerphilly", "Cairnsmore", "Calenzana", "Cambazola", "Camembert de Normandie", 
       "Four Herb Gouda", "Fourme d' Ambert", "Fourme de Haute Loire", "Fourme de Montbrison", 
       "Washed Rind Cheese (Australian)", "Waterloo", "Weichkaese", "Wellington", 
      "Wensleydale", "White Stilton", "Whitestone Farmhouse", "Wigmore", "Woodside Cabecou", 
      "Xanadu", "Xynotyro", "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue", 
      "Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano"}; 
// ContentValues values = new ContentValues(); 
private final String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; 
    private static final String tag = "Main"; 
    private Button selectedDayMonthYearButton; 
    private Button currentMonth; 
    private ImageView prevMonth; 
    private ImageView nextMonth; 
    private GridView calendarView; 
    private GridCellAdapter adapter; 
    private Calendar _calendar; 
    private int month, year; 
    private final DateFormat dateFormatter = new DateFormat(); 
    private static final String dateTemplate = "MMMM yyyy"; 
    private PopupWindow pw,pw1; 
    TextView txt1; 
    static ViewHolder holder; 
    String title; 
    private void getRequestParameters() 
    { 
    Intent intent = getIntent(); 
    if (intent != null) 
    { 
     Bundle extras = intent.getExtras(); 
     if (extras != null) 
     { 
     if (extras != null) 
     { 
      Log.d(tag, "+++++----------------->" + extras.getString("params")); 
     } 
     } 
    } 
    } 


    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.simple_calendar_view); 

    _calendar = Calendar.getInstance(Locale.getDefault()); 
    month = _calendar.get(Calendar.MONTH); 
    Log.v("Months", ""+month); 
    year = _calendar.get(Calendar.YEAR); 
    Log.v("YEAR", ""+year); 

    selectedDayMonthYearButton = (Button) this.findViewById(R.id.selectedDayMonthYear); 
    selectedDayMonthYearButton.setText("Selected: "); 

    prevMonth = (ImageView) this.findViewById(R.id.prevMonth); 
    prevMonth.setOnClickListener(this); 

    currentMonth = (Button) this.findViewById(R.id.currentMonth); 
    currentMonth.setText(dateFormatter.format(dateTemplate, _calendar.getTime())); 

    nextMonth = (ImageView) this.findViewById(R.id.nextMonth); 
    nextMonth.setOnClickListener(this); 

    calendarView = (GridView) this.findViewById(R.id.calendar); 

    // Initialised 
    adapter = new GridCellAdapter(getApplicationContext(), R.id.day_gridcell, month, year); 
    adapter.notifyDataSetChanged(); 
    calendarView.setAdapter(adapter); 
    } 



    @Override 
    public void onClick(View v) 
    { 
    if (v == prevMonth) 
    { 
     if (month <= 1) 
     { 
     month = 11; 
     year--; 
     } else 
     { 
     month--; 
     } 

     adapter = new GridCellAdapter(getApplicationContext(), R.id.day_gridcell, month, year); 
     _calendar.set(year, month, _calendar.get(Calendar.DAY_OF_MONTH)); 
     currentMonth.setText(months[_calendar.get(Calendar.MONTH)] + "-" +_calendar.get(Calendar.YEAR)); 
     //currentMonth.setText(_calendar.getTime().toString()); 

     adapter.notifyDataSetChanged(); 
     calendarView.setAdapter(adapter); 
    } 
    if (v == nextMonth) 
    { 
     if (month >= 11) 
     { 
     month = 0; 
     year++; 
     } else 
     { 
     month++; 
     } 

     adapter = new GridCellAdapter(getApplicationContext(), R.id.day_gridcell, month, year); 
     _calendar.set(year, month, _calendar.get(Calendar.DAY_OF_MONTH)); 
     currentMonth.setText(months[_calendar.get(Calendar.MONTH)] + "-" +_calendar.get(Calendar.YEAR)); 
     //currentMonth.setText(_calendar.getTime().toString()); 
     adapter.notifyDataSetChanged(); 
     calendarView.setAdapter(adapter); 
    } 
    } 

    // Inner Class 
    public class GridCellAdapter extends BaseAdapter implements OnClickListener 
    { 
    final ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE); 
    private static final String tag = "GridCellAdapter"; 
    private final Context _context; 
    private final List<String> list; 
    private final String[] weekdays = new String[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; 


private final int[] daysOfMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 
private final int month, year; 
int daysInMonth, prevMonthDays; 
private final int currentDayOfMonth; 
private Button gridcell; 

// Days in Current Month 
public GridCellAdapter(Context context, int textViewResourceId, int month, int year) 
{ 
    super(); 
    this._context = context; 
    this.list = new ArrayList<String>(); 
    this.month = month; 
    this.year = year; 

    Log.d(tag, "Month: " + month + " " + "Year: " + year); 
    Calendar calendar = Calendar.getInstance(); 
    currentDayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); 

    printMonth(month, year); 
} 

public String getItem(int position) 
{ 
    return list.get(position); 
} 

@Override 
public int getCount() 
{ 
    return list.size(); 
} 

private void printMonth(int mm, int yy) 
{ 
    // The number of days to leave blank at 
    // the start of this month. 
    int trailingSpaces = 0; 
    int leadSpaces = 0; 
    int daysInPrevMonth = 0; 
    int prevMonth = 0; 
    int prevYear = 0; 
    int nextMonth = 0; 
    int nextYear = 0; 

    GregorianCalendar cal = new GregorianCalendar(yy, mm, currentDayOfMonth); 

    // Days in Current Month 
    daysInMonth = daysOfMonth[mm]; 
    int currentMonth = mm; 
    if (currentMonth == 11) 
    { 
    prevMonth = 10; 
    daysInPrevMonth = daysOfMonth[prevMonth]; 
    nextMonth = 0; 
    prevYear = yy; 
    nextYear = yy + 1; 
    } else if (currentMonth == 0) 
    { 
    prevMonth = 11; 
    prevYear = yy - 1; 
    nextYear = yy; 
    daysInPrevMonth = daysOfMonth[prevMonth]; 
    nextMonth = 1; 
    } else 
    { 
    prevMonth = currentMonth - 1; 
    nextMonth = currentMonth + 1; 
    nextYear = yy; 
    prevYear = yy; 
    daysInPrevMonth = daysOfMonth[prevMonth]; 
    } 

    // Compute how much to leave before before the first day of the 
    // month. 
    // getDay() returns 0 for Sunday. 
    trailingSpaces = cal.get(Calendar.DAY_OF_WEEK) - 1; 

    if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 1) 
    { 
    ++daysInMonth; 
    } 

    // Trailing Month days 
    for (int i = 0; i < trailingSpaces; i++) 
    { 
    list.add(String.valueOf((daysInPrevMonth - trailingSpaces + 1) + i) + "-GREY" + "-" + months[prevMonth] + "-" + prevYear); 
    } 

    // Current Month Days 
    for (int i = 1; i <= daysInMonth; i++) 
    { 
    Log.v("Current Days",""+String.valueOf(i) + "-WHITE" + "-" + months[mm] + "-" + yy); 
    list.add(String.valueOf(i) + "-WHITE" + "-" + months[mm] + "-" + yy); 
    } 

    // Leading Month days 
    for (int i = 0; i < list.size() % 7; i++) 
    { 
    Log.d(tag, "NEXT MONTH:= " + months[nextMonth]); 
    list.add(String.valueOf(i + 1) + "-GREY" + "-" + months[nextMonth] + "-" + nextYear); 
    } 
} 

@Override 
public long getItemId(int position) 
{ 
    return position; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) 
{ 
    Log.d(tag, "getView ..."); 
    View row = convertView; 
    if (row == null) 
    { 
    // ROW INFLATION 
    Log.d(tag, "Starting XML Row Inflation ... "); 
    LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    row = inflater.inflate(R.layout.day_gridcell, parent, false); 

    Log.d(tag, "Successfully completed XML Row Inflation!"); 
    } 

    // Get a reference to the Day gridcell 
    gridcell = (Button) row.findViewById(R.id.day_gridcell); 
    gridcell.setOnClickListener(this); 

    // ACCOUNT FOR SPACING 

    Log.d(tag, "Current Day: " + currentDayOfMonth); 
    String[] day_color = list.get(position).split("-"); 
    Log.d("setText", "Current Day: " + day_color[0]); 
    gridcell.setText(day_color[0]); 
    gridcell.setTag(day_color[0] + "-" + day_color[2] + "-" + day_color[3]); 
    //gridcell.setText(clipBoard.getText()); 

    if (day_color[1].equals("GREY")) 
    { 
    gridcell.setTextColor(Color.LTGRAY); 
    } 
    if (day_color[1].equals("WHITE")) 
    { 
    gridcell.setTextColor(Color.WHITE); 
    } 
    if (position == currentDayOfMonth) 
    { 
    gridcell.setTextColor(Color.BLUE); 
    } 

    return row; 
} 
@Override 
public void onClick(View view) 
{ 

LayoutInflater inflater = (LayoutInflater) Main.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    // inflate our view from the corresponding XML file 
    final View layout = inflater.inflate(R.layout.popup, (ViewGroup)findViewById(R.id.popup_menu_root)); 
    final View layout1 = inflater.inflate(R.layout.event, (ViewGroup)findViewById(R.id.pop_event)); 
    final String date_month_year = (String) view.getTag(); 

    pw = new PopupWindow(layout, 200,75, true); 
TextView txt =(TextView)pw.getContentView().findViewById(R.id.pop_txt); 
txt.setText(date_month_year); 
    holder = new ViewHolder(); 
    holder.text1 = (TextView) view.findViewById(R.id.pop_txt); 
    //holder.text1.setText("HIIIIIII"); 

    pw.dismiss(); 
    pw.showAtLocation(layout, Gravity.CENTER_VERTICAL, 10, 30); 


    Toast.makeText(getApplicationContext(), date_month_year, Toast.LENGTH_SHORT).show(); 
    selectedDayMonthYearButton.setText("Selected: " + date_month_year); 
    Log.v("Button ID",""+R.id.bttn2); 

    pw.getContentView().findViewById(R.id.bttn2).setOnClickListener(new OnClickListener(){ 

    @Override 
    public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    //LayoutInflater inflater = (LayoutInflater) Main.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     // inflate our view from the corresponding XML file 


    pw1 = new PopupWindow(layout1, 270,370, true); 

    TextView txt1 =(TextView)pw1.getContentView().findViewById(R.id.event_head); 
    txt1.setText(date_month_year); 
    pw1.dismiss(); 
    pw1.showAtLocation(layout1, Gravity.CENTER, 7, 20); 

    setListAdapter(new ArrayAdapter<String>(Main.this, 
        android.R.layout.simple_list_item_1, mStrings)); 
      getListView().setTextFilterEnabled(true); 
    } 

    }); 

    layout1.findViewById(R.id.event_bttn2).setOnClickListener(new OnClickListener(){ 

    @Override 
    public void onClick(View v) { 
    // TODO Auto-generated method stub 
    pw1.dismiss(); 
    pw.dismiss(); 
    } 

    }); 

    final EditText et=(EditText)layout1.findViewById(R.id.event_edit_txt); 

    layout1.findViewById(R.id.event_bttn1).setOnClickListener(new OnClickListener(){ 

    @Override 
    public void onClick(View v) { 
    // TODO Auto-generated method stub 

    Log.v("GET TEXT",""+et.getText()); 
    clipBoard.setText(et.getText()); 
    Log.v("SET TEXT",""+clipBoard.getText()); 
    //gridcell.getId(); 
    title=clipBoard.getText()+""; 
    Log.v("title",""+title); 






    } 



    }); 

} 








} 



    static class ViewHolder { 
    TextView text1; 

    } 




} 
+0

Sie sollten Ihr Protokoll veröffentlichen ... –

Antwort

0

Ich denke, dass Sie mehrere Dialoge anzeigen möchten. Eigentlich können Sie einen Dialog auf einmal erstellen, aber Sie können mehrere Dialoge mit Fragment erstellen. Siehe this Antwort.