3

私はリストアクティビティを複数の行で構成し、各行にテキストと2つのボタンを含むオープンアクティビティを作成し、そのうちの1つは無限ギャラリーを開き、もう1つはダイアログを開き、各ダイアログには異なる文字列がありました。

私は20行あるので、ダイアログを20回追加しますが、これは冗長です。また、うまく機能しますが、私がしたことよりも良いアプローチがあると思います。

それを手に入れるための助けをいただければ幸いです、ありがとう

MyDay クラス:

public class MyDay extends Activity {
final Context context = this;
private Button button;
TextView tv1,tv2,tv3,tv4;
String day;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.Layou
          tParams.FLAG_FULLSCREEN); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    Boolean customTitleSupported =       
         requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);     
    setContentView(R.layout.day);  

    if (customTitleSupported) {          
     getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);  } 

    initializeTextViews(); }

private void initializeTextViews() {
    tv1=(TextView)findViewById(R.id.title_tv1); 
    tv1.setTypeface(FontFactory.getBFantezy(getBaseContext()));

    tv2=(TextView)findViewById(R.id.day_tv1);
    tv2.setTypeface(FontFactory.getBFantezy(getBaseContext()));

    tv3=(TextView)findViewById(R.id.day_tv3);
    tv3.setTypeface(FontFactory.getBFantezy(getBaseContext()));

     day=getIntent().getStringExtra("cheese");

    if(day.equalsIgnoreCase("Day1")){
        tv1.setText("First Day");       
        tv2.setText(Html.fromHtml(getString(R.string.beginning)));  
        tv3.setText(Html.fromHtml(getString(R.string.day1))); 

        button = (Button) findViewById(R.id.city_button);        
        button.setOnClickListener(new OnClickListener() { 
      public void onClick(View arg0) { 
        // custom dialog
        final Dialog dialog = new Dialog(context,R.style.cust_dialog);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);           
        dialog.setContentView(R.layout.custom_dialog); 
        // set the custom dialog components - text, image and button
        TextView text = (TextView) dialog.findViewById(R.id.dialog_text);
        text.setTypeface(FontFactory.getBFantezy(getBaseContext()));                
        text.setText(Html.fromHtml(getString(R.string.torusim_places_1)));

    Button dialogButton = (Button) dialog.findViewById(R.id.dialog_Button);             
                dialogButton.setTypeface(FontFactory.getBFantezy(getBaseContext()));
        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                dialog.dismiss();}
                         });
                dialog.show(); }
                         }); }

     else if(day.equalsIgnoreCase("Day2")){
        tv1.setText("Second Day");
        tv2.setText(Html.fromHtml(getString(R.string.beginning)));
        tv3.setText(Html.fromHtml(getString(R.string.day2))); 

        button = (Button) findViewById(R.id.city_button);        
        button.setOnClickListener(new OnClickListener() {    
          public void onClick(View arg0) {   
            // custom dialog
        final Dialog dialog = new Dialog(context,R.style.cust_dialog);                  
                 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);          
         dialog.setContentView(R.layout.custom_dialog);  

    TextView text = (TextView) dialog.findViewById(R.id.dialog_text);               
              text.setTypeface(FontFactory.getBFantezy(getBaseContext()));              
        text.setText(Html.fromHtml(getString(R.string.torusim_places_2)));

    Button dialogButton = (Button) dialog.findViewById(R.id.dialog_Button);         
         dialogButton.setTypeface(FontFactory.getBFantezy(getBaseContext()));
            // if button is clicked, close the custom dialog
            dialogButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss(); }
                            });  
                    dialog.show(); }
                        }); }
     else if(day.equalsIgnoreCase("Day3")){
        tv1.setText("Third Day");
        tv2.setText(Html.fromHtml(getString(R.string.beginning)));
        tv3.setText(Html.fromHtml(getString(R.string.day3))); 

        button = (Button) findViewById(R.id.city_button);        
        button.setOnClickListener(new OnClickListener() {    
          public void onClick(View arg0) {   
        // custom dialog
        final Dialog dialog = new Dialog(context,R.style.cust_dialog);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);           
                dialog.setContentView(R.layout.custom_dialog);                  
        TextView text = (TextView) dialog.findViewById(R.id.dialog_text);               
                  text.setTypeface(FontFactory.getBFantezy(getBaseContext()));              
               text.setText(Html.fromHtml(getString(R.string.torusim_places_3)));

    Button dialogButton = (Button) dialog.findViewById(R.id.dialog_Button);             
            dialogButton.setTypeface(FontFactory.getBFantezy(getBaseContext()));
            // if button is clicked, close the custom dialog
        ialogButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss(); }
                            });  
                    dialog.show(); }
                        }); 
                                   }
                                 }

  // this continuing repeated till day 20 // 

 public void handleClick(View v){

    //Create an intent to start the new activity.

    Intent intent = new Intent();
    intent.setClass(this,DayGallery.class);
    intent.putExtra("dayname",day);
    startActivity(intent);

                  }
            }
4

2 に答える 2