java - Is there a way to change android.R.layout.simple_list_item_1, to my custom layout? -
part of code
package com.example.pass; import java.text.simpledateformat; import java.util.arraylist; import java.util.calendar; import android.app.activity; import android.app.datepickerdialog; import android.app.datepickerdialog.ondatesetlistener; import android.app.dialog; import android.app.timepickerdialog; import android.app.timepickerdialog.ontimesetlistener; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.text.format.dateformat; import android.util.log; import android.view.keyevent; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.view.onclicklistener; import android.view.view.onkeylistener; import android.view.viewgroup; import android.widget.adapterview; import android.widget.adapterview.onitemlongclicklistener; import android.widget.arrayadapter; import android.widget.button; import android.widget.cursoradapter; import android.widget.datepicker; import android.widget.edittext; import android.widget.listview; import android.widget.textview; import android.widget.timepicker; import android.widget.toast; public class permission extends actionbaractivity implements onclicklistener, onkeylistener{ edittext date; edittext time; edittext username; edittext usersurname; button btnok; button cancel; edittext name; string surname; button clear; listview list; arraylist<string> items; arrayadapter<string> aa; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_permission); list = (listview)findviewbyid(r.id.listview1); items = new arraylist<string>(); aa = new arrayadapter<string>(this, android.r.layout.simple_list_item_1,items); list.setadapter(aa); // include dialog.xml file // set dialog title final dialog dialog = new dialog(permission.this); dialog.setcontentview(r.layout.dialog_permission); dialog.settitle("custom dialog"); clear = (button)findviewbyid(r.id.clear); button add = (button) findviewbyid(r.id.add); // create custom dialog object // set values custom dialog components - text, image , button username = (edittext) dialog.findviewbyid(r.id.dialog_username); usersurname = (edittext)dialog.findviewbyid(r.id.dialog_usersurname); time = (edittext)dialog.findviewbyid(r.id.dialog_time2); date = (edittext)dialog.findviewbyid(r.id.dialog_date2); btnok = (button) dialog.findviewbyid(r.id.ok); cancel = (button) dialog.findviewbyid(r.id.cancel); btnok.setonclicklistener(this); username.setonkeylistener(this); add.setonclicklistener(new view.onclicklistener() { public void onclick(view arg0) { date.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //to show current date in datepicker calendar mcurrentdate=calendar.getinstance(); int myear = mcurrentdate.get(calendar.year); int mmonth = mcurrentdate.get(calendar.month); int mday = mcurrentdate.get(calendar.day_of_month); datepickerdialog mdatepicker=new datepickerdialog(permission.this, new ondatesetlistener() { public void ondateset(datepicker datepicker, int selectedyear, int selectedmonth, int selectedday) { // todo auto-generated method stub /* code date , time */ date.settext(selectedyear+"-"+(selectedmonth+1)+"-"+selectedday); } },myear, mmonth, mday); mdatepicker.settitle("select date"); mdatepicker.show(); } }); time.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //to show current date in datepicker calendar mcurrenttime=calendar.getinstance(); int mhour = mcurrenttime.get(calendar.hour_of_day); int mminute = mcurrenttime.get(calendar.minute); timepickerdialog mtimepicker=new timepickerdialog(permission.this, new ontimesetlistener() { public void ontimeset(timepicker timepicker, int selectedhour, int selectedminute ) { // todo auto-generated method stub /* code date , time */ if (selectedminute<10){ time.settext(selectedhour+":"+"0"+(selectedminute)+""+"val"); } else time.settext(selectedhour+":"+(selectedminute)); } },mhour, mminute, false); mtimepicker.settitle("select date"); mtimepicker.show(); } }); cancel.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub //to show current date in datepicker dialog.dismiss(); } }); // ok.setonclicklistener(new onclicklistener() { /* @override public void onclick(view v) { // todo auto-generated method stub this.additem(this.username.gettext().tostring()); //converting text in string... system.out.println(name); } });*/ clear.setonclicklistener(new onclicklistener() { public void onclick(view v) { } }); dialog.show(); } }); } private void additem(string item){ if(item.length()>0){ this.items.add(item); this.aa.notifydatasetchanged(); this.username.settext(""); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.permission, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } @override public boolean onkey(view v, int keycode, keyevent event) { // todo auto-generated method stub if(event.getaction()==keyevent.action_down&&keycode==keyevent.keycode_dpad_center){ this.additem(this.username.gettext().tostring()); this.additem(this.usersurname.gettext().tostring()); } return false; } @override public void onclick(view v) { // todo auto-generated method stub if(v == this.btnok){ this.additem(this.username.gettext().tostring()); this.additem(this.usersurname.gettext().tostring()); } } }
everytime try change custom layout crashes, dont know how not losing dialog window, because text reading in custom dialog. know maybe creating new adapter class can solve problem want try way.
use ctrl + left click on android.r.layout.simple_list_item_1
open it.
copy contents own xml layout file, , edit wish.
change
android.r.layout.simple_list_item_1
to
r.layout.your_layout
Comments
Post a Comment