-4

下面是我的代码,我只想在文本上显示特定值,当单击显示完整值时,这个引用不能帮助我 android 如何从给定字符串中减去字符串

               Button e01;
              String value;

            String[] days = new String[7];

             for (int i = 0; i < 7; i++) {


         Log.d("TAG",df.format(calendarGlobal.getTime()));
         days[i] = df.format(calendarGlobal.getTime());  

              //i want to display only 11
              days[1]=    // 2013/09/11
         String[] stringArray = days[1].split("/");
         String elevenString = stringArray[stringArray.length-1];

    e01.setText(elevenString);
    e01.setTag(days[1]);


    //e01.setText(elevenString); show error if i replace  /e01.setText(elevenString);
   ///   with  e01.setTag(days[1]);  is show same value on text and on click on toast i 
  //  want  to show only"11" on e01.setText("11");
  //  when click on e01 show full value on Toast   // 2013/09/11

                  @Override
        public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {

      case R.id.e01:


      value = e01.getTag().toString();
             Toast.makeText(this, value, Toast.LENGTH_SHORT)    .show();








              public void calculateWeek(int currentweekno) {
    // TODO Auto-generated method stub
 //   days.clear();
    // Set the calendar to monday of the current week
    // calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
     calendarGlobal = Calendar.getInstance();
    DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    calendarGlobal.add(Calendar.WEEK_OF_YEAR, +currentweekno);
    calendarGlobal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    String[] days = new String[7];
    for (int i = 0; i < 7; i++) {
     //   days.add(df.format(calendarGlobal.getTime()));
         Log.d("TAG",df.format(calendarGlobal.getTime()));
         days[i] = df.format(calendarGlobal.getTime());




        e01.setText("11");
         e01.setTag(days[1]);
4

1 回答 1

0

您需要对类型进行一些编辑

首先,在 onClick 方法上,将 value 更改为 String value,将 e01 更改为 v

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
        case R.id.e01:
        String value = v.getTag().toString();       // change here
        Toast.makeText(this, value, Toast.LENGTH_SHORT) .show();

其次,将按钮 e01 更改为跟随并实例化它。在您的代码中,您忘记实例化您的按钮。

 Button e01 = (Button) findElementById(R.id.e01);
于 2013-09-14T10:41:39.393 回答