Как получить данные из диалогового окна для просмотра списка в Android 2.1? - PullRequest
0 голосов
/ 26 августа 2011

все Я динамически создал список просмотра. Теперь я хочу изменить имя списка / элементы списка, или я хочу получить содержимое под каждой строкой, но содержимое исходит из dialogbox. Можно ли получить данные из диалогового окна в списке просмотра? Как этого добиться? ? Может ли какой-либо один руководство или дать пример кода того же самого?

Заранее спасибо -

  public class Tdate extends Activity 
    {

private ListView lView;
private String lv_items[] = { "Birth_Date", "Anniversary_Date", "Joining_Date","Meeting_Date","Appraisal_Date","Anniversary_Date", "Joining_Date","Meeting_Date","Appraisal_Date"};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tdate);
    Button customdate = (Button)findViewById(R.id.customdate);  
    lView = (ListView) findViewById(R.id.ListView01);
    lView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, lv_items));
    lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    lView.setOnItemClickListener(new OnItemClickListener()
    {
        @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
        {
                     showDateTimeDialog();
        }

    });
}

private void showDateTimeDialog()
{
    // Create the dialog
    final Dialog mDateTimeDialog = new Dialog(this);
    // Inflate the root layout
    final RelativeLayout mDateTimeDialogView = (RelativeLayout) getLayoutInflater().inflate(R.layout.date_time_dialog, null);
    // Grab widget instance
    final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView.findViewById(R.id.DateTimePicker);
    // Check is system is set to use 24h time (this doesn't seem to work as expected though)
    final String timeS = android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.TIME_12_24);
    final boolean is24h = !(timeS == null || timeS.equals("12"));

    // Update demo TextViews when the "OK" button is clicked 
    ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime)).setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            mDateTimePicker.clearFocus();

            ((TextView) findViewById(R.id.Date)).setText(mDateTimePicker.get(Calendar.YEAR) + "/" + (mDateTimePicker.get(Calendar.MONTH)+1) + "/"
                    + mDateTimePicker.get(Calendar.DAY_OF_MONTH));
            if (mDateTimePicker.is24HourView()) {
                ((TextView) findViewById(R.id.Time)).setText(mDateTimePicker.get(Calendar.HOUR_OF_DAY) + ":" + mDateTimePicker.get(Calendar.MINUTE));
            } else {
                ((TextView) findViewById(R.id.Time)).setText(mDateTimePicker.get(Calendar.HOUR) + ":" + mDateTimePicker.get(Calendar.MINUTE) + " "
                        + (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM"));
            }

            mDateTimeDialog.dismiss();
        }
    });

    // Cancel the dialog when the "Cancel" button is clicked
    ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog)).setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            mDateTimeDialog.cancel();
        }
    });


    // Reset Date and Time pickers when the "Reset" button is clicked
    ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime)).setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            mDateTimePicker.reset();
        }
    });

    // Setup TimePicker
    mDateTimePicker.setIs24HourView(is24h);
    // No title on the dialog window
    mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Set the dialog content view
    mDateTimeDialog.setContentView(mDateTimeDialogView);
    // Display the dialog
    mDateTimeDialog.show();
}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...