Bear with me as this is my first app. My app isn't too revolutionary but I'd like to make it more user-friendly by implementing some custom pickers. For instance, a date picker that uses a calender view or a spinner-like picker that flows horizontally (much like SetCPU). Unfortunately, I don't even know where to start with building custom ui components like these.
Asked
Active
Viewed 6,388 times
4 Answers
4
I guess following skeleton code would help to provide some flexibility in your application that you desire.
/* Simple Dialog
Dialog dialog = new Dialog(this);
dialog.setTitle("Hello");
dialog.show();
*/
/* Inflating an layout as the Dialog
Dialog loginDialog = new Dialog(this);
View layout = LayoutInflater.from(this).inflate(R.layout.login, null);
loginDialog.setContentView(layout);
Button btn = (Button)(layout.findViewById(R.id.button1));
final EditText txt = (EditText) layout.findViewById(R.id.editText1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), txt.getText().toString(), Toast.LENGTH_SHORT).show();
txt.setText("Ahmedabad");
}
});
loginDialog.show();
/* ProgreessBar Dialog (you need to implement thread)
ProgressDialog dialog = new ProgressDialog(this);
dialog.setProgressStyle(2);
dialog.show();
*/
/* Alert Dialog to alert a mesage or an error or customize exception like Enter the field, etc.
AlertDialog dialog = new AlertDialog.Builder(this).create();
dialog.setMessage("Message");
dialog.setIcon(R.drawable.ic_launcher);
dialog.setTitle("Done");
dialog.show();
*/
/* ------------------- Binding array items into the spinner ---------------------------
sp = (Spinner)findViewById(R.id.spinner1);
String bloodgroups[]={
"A +ve","B +ve","O +ve","AB +ve","A -ve","B -ve","O -ve","AB -ve"
};
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout .simple_spinner_dropdown_item,bloodgroups);
sp.setAdapter(adapter);
*/
/* DatePicker Dialog Code: I have used a button whose click event bring datepicker dialog into focus
Button btnselDate = (Button)findViewById(R.id.btnseldate); // date select button
// ----------------------------- DATE PICKER DIALOG PROMPT ---------------------
btnselDate.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
showDialog(1);
}
});
@Override
protected Dialog onCreateDialog(int id) {
DatePickerDialog dialog = new DatePickerDialog(this, new OnDateSetListener()
{
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
((EditText)findViewById(R.id.txtdate)).setText(dayOfMonth + "/" + monthOfYear + "/" + year);
}
}, new GregorianCalendar().get(Calendar.YEAR), new GregorianCalendar().get(Calendar.MONTH), new GregorianCalendar().get(Calendar.DAY_OF_MONTH));
return dialog;
}
*/

Rushabh
- 385
- 2
- 5
- 14
-
1@mango: Kindly Mark my Answer as Appropriate if you find the answer worth and answers your question. – Rushabh Sep 03 '12 at 00:49
2
Android's default widget are simple, but by mixing them you can build your own custom widgets. Read more about this here.

S.D.
- 29,290
- 3
- 79
- 130
0
Create a custom class which extends View. Then you can set the size and control what is drawn on the Canvas and how it will respond to touch events. There are plenty of examples around regarding creating 'widgets'. Reto Meiers book has a good example where he creates a compass.

John J Smith
- 11,435
- 9
- 53
- 72
0
well, I've decided to give up for now, but for anyone else this webpage really helped me at least to wrap my head around it.
http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/

mango
- 5,577
- 4
- 29
- 41