Results 1 to 3 of 3
Thread: problem creating new thread
- 01-23-2011, 08:19 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
-
- 01-23-2011, 08:40 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 5
- Rep Power
- 0
Mmmm Ok I'm just going to post my problem here, hopefully somebody can help. Im trying to create an application which will display both a time and date button from which users can then select from. Below is my code but for some reason I have and error for this line:
DatePicker.OnDateSetListener d=new DatePicker.OnDateSetListener() {
Stating that DatePicker.OnDateSetListener cannot be resolved to a type. Can anybody help me with this. Here is the rest of the code.
package andoid.application;
import java.text.DateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
public class PurchaseParkingActivity extends Activity {
DateFormat fmtDateAndTime=DateFormat.getDateTimeInstance();
TextView dateAndTimeLabel;
Calendar dateAndTime=Calendar.getInstance();
DatePicker.OnDateSetListener d=new DatePicker.OnDateSetListener() {
public void dateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
dateAndTime.set(Calendar.YEAR, year);
dateAndTime.set(Calendar.MONTH, monthOfYear);
dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
TimePicker.OnTimeSetListener t=new TimePicker.OnTimeSetListener() {
public void timeSet(TimePicker view, int hourOfDay,
int minute) {
dateAndTime.set(Calendar.HOUR, hourOfDay);
dateAndTime.set(Calendar.MINUTE, minute);
updateLabel();
}
};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.dateBtn);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new DatePickerDialog(PurchaseParkingActivity.this,
d,
dateAndTime.get(Calendar.YEAR),
dateAndTime.get(Calendar.MONTH),
dateAndTime.get(Calendar.DAY_OF_MONTH),
Calendar.SUNDAY).show();
}
});
btn=(Button)findViewById(R.id.timeBtn);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new TimePickerDialog(PurchaseParkingActivity.this,
t, "Set the time",
dateAndTime.get(Calendar.HOUR),
dateAndTime.get(Calendar.MINUTE),
true).show();
}
});
dateAndTimeLabel=(TextView)findViewById(R.id.dateA ndTime);
updateLabel();
}
private void updateLabel() {
dateAndTimeLabel.setText(fmtDateAndTime
.format(dateAndTime.getTime()));
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/dateAndTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:id="@+id/dateBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set the Date"
/>
<Button android:id="@+id/timeBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set the Time"
/>
</LinearLayout>
Thanks in Advance Sean :)
Similar Threads
-
Creating new threads from another thread
By enzom83 in forum Threads and SynchronizationReplies: 1Last Post: 12-03-2010, 10:15 PM -
a way for creating a Thread
By arefeh in forum New To JavaReplies: 6Last Post: 01-02-2010, 05:37 PM -
Creating a thread that modifies UI
By prueba2306 in forum EclipseReplies: 2Last Post: 08-01-2008, 01:26 PM -
Creating a Thread using the Runnable interface
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:31 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks