У меня проблема, спасибо, что помогли мне создать 3 textview, используя «while» в действии. java, но я хочу, чтобы при нажатии кнопки установить текст в textView (я делаю это), но при изменении даты, текст textView также изменился
я попробую это, но не сработает ... его метод кнопки:
public void go2(View view){
//Dr choose date
Date date1= (Date) new Date
(picker.getYear()-1900, picker.getMonth(), picker.getDayOfMonth());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
dateString = sdf.format(date1);
System.out.println(dateString);
final LinearLayout lm=(LinearLayout)findViewById(R.id.DrpageAct);
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
Cursor allPatient=DrPage.myDB.ViewAllPatient(idDr,dateString);
allPatient.moveToFirst();
if (allPatient == null) {
Toast.makeText(DrPage.this, "you have no Apointment", Toast.LENGTH_LONG).show();
}else {
int num=0;
//create for) for show patient
while (allPatient.moveToNext()) {
num++;
String fnameDb = allPatient.getString(0);
String lnameDb = allPatient.getString(1);
String timeDb = allPatient.getString(2);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
//create textView
rollNo = new TextView(this);
rollNo.setText(" " + num + " ");
ll.addView(rollNo);
name = new TextView(this);
name.setText(" " + fnameDb+" "+lnameDb);
name.setWidth(300);
ll.addView(name);
date = new TextView(this);
date.setText(timeDb + " ");
date.setWidth(150);
ll.addView(date);
lm.addView(ll);
}
rollNo.setText("");
name.setText("");
date.setText("");
}
}
и весь код
public class DrPage extends AppCompatActivity {
static MyDB myDB;
public int idDr;
public String DRname;
public String DrIdS;
public String nameDr;
DatePicker picker;
public String dateString;
Button btn;
public TextView rollNo;
public TextView name;
public TextView date;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dr_page);
myDB = new MyDB(this);
picker=(DatePicker)findViewById(R.id.datePicker2);//date
btn=(Button)findViewById(R.id.btn1);
//get Dr id
nameDr= MainActivity.p();
Cursor data = myDB.getIDdr(nameDr);
while (data.moveToNext()) {
DrIdS = data.getString(0);
idDr=Integer.parseInt(DrIdS);
}
System.out.println("dr id " + idDr);
}
public void go2(View view){
//Dr choose date
Date date1= (Date) new Date
(picker.getYear()-1900, picker.getMonth(), picker.getDayOfMonth());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
dateString = sdf.format(date1);
System.out.println(dateString);
final LinearLayout lm=(LinearLayout)findViewById(R.id.DrpageAct);
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
Cursor allPatient=DrPage.myDB.ViewAllPatient(idDr,dateString);
allPatient.moveToFirst();
if (allPatient == null) {
Toast.makeText(DrPage.this, "you have no Apointment", Toast.LENGTH_LONG).show();
}else {
int num=0;
//create for) for show patient
while (allPatient.moveToNext()) {
num++;
String fnameDb = allPatient.getString(0);
String lnameDb = allPatient.getString(1);
String timeDb = allPatient.getString(2);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
//create textView
rollNo = new TextView(this);
rollNo.setText(" " + num + " ");
ll.addView(rollNo);
name = new TextView(this);
name.setText(" " + fnameDb+" "+lnameDb);
name.setWidth(300);
ll.addView(name);
date = new TextView(this);
date.setText(timeDb + " ");
date.setWidth(150);
ll.addView(date);
lm.addView(ll);
}
rollNo.setText("");
name.setText("");
date.setText("");
}
}
}
пожалуйста, помогите мне, как я могу это исправить?