1

在我的第四节课中,选定的文本不会只显示粗体早餐会显示粗体午餐和晚餐当我按下 img2 或 img3 时不会显示粗体告诉我我会做什么?所有值都显示在 Toast 上,但只有当 pres img 是 make 时才会使文本变为粗体 早餐将是粗体 午餐和晚餐不显示粗体

  img1.setOnClickListener(new View.OnClickListener() {

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

            Intent iMenuList = new Intent(thirdstep.this,
                    fourthscreen.class);

            iMenuList.putExtra("Menuitem", txt1.getText().toString());

            startActivity(iMenuList);

        }
    });

    img2.setOnClickListener(new View.OnClickListener() {

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

            Intent iMenuList = new Intent(thirdstep.this,
                    fourthscreen.class);

            iMenuList.putExtra("Menuitem", txt2.getText().toString());

            startActivity(iMenuList);

        }
    });

    img3.setOnClickListener(new View.OnClickListener() {

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

            Intent iMenuList = new Intent(thirdstep.this,
                    fourthscreen.class);

            iMenuList.putExtra("Menuitem", txt3.getText().toString());

            startActivity(iMenuList);

        }
    });

}

  }


       public class fourthscreen extends Activity

            Breakfast = (TextView) findViewById(R.id.txtfourth1);
    Lunch = (TextView) findViewById(R.id.txtfourth2);
    Supper = (TextView) findViewById(R.id.txtfourth3);


         Bundle bundle = this.getIntent().getExtras();
     String param1 = bundle.getString("Menuitem");

                 Toast.makeText(fourthscreen.this, param1, Toast.LENGTH_LONG).show();
     if(param1.equalsIgnoreCase("BreakFast"))
     {
         Breakfast.setTypeface(null, Typeface.BOLD);
     }
     else 
         if(param1.equalsIgnoreCase("Lunch"))
         {
             Lunch.setTypeface(null, Typeface.BOLD);
         }
         else 
             if(param1.equalsIgnoreCase("Supper"))
             {
                 Lunch.setTypeface(null, Typeface.BOLD);
             }
4

3 回答 3

0
yourTextView.setTypeface(null,Typeface.DEFAULT_BOLD);

尝试默认粗体,它适用于我

于 2013-08-02T07:23:31.780 回答
0

在您的 xml 中,只需在 TextView 标记中写入以下行

android:textStyle="bold"
于 2013-08-02T07:23:33.667 回答
0

首先检查String param1 = bundle.getString("Menuitem");p* aram1 * 值,您是否仅通过“BreakFast”、“Lunch”和“Supper”?

if(param1.equalsIgnoreCase("BreakFast"))
{
         Breakfast.setTypeface(null, Typeface.BOLD);
         Lunch.setTypeface(null, Typeface.NORMAL);
        Supper.setTypeface(null, Typeface.NORMAL);
}
else if(param1.equalsIgnoreCase("Lunch"))
{
         Lunch.setTypeface(null, Typeface.BOLD);
         Breakfast.setTypeface(null, Typeface.NORMAL);
        Supper.setTypeface(null, Typeface.NORMAL);
}
else if(param1.equalsIgnoreCase("Supper"))
{
        Supper.setTypeface(null, Typeface.BOLD);
        Lunch.setTypeface(null, Typeface.NORMAL);
        Breakfast.setTypeface(null, Typeface.NORMAL);
}
于 2013-08-02T07:23:54.453 回答