示例#1
0
  /**
   * Sets the Picture Item for this activity and updates all the elements accordingly.
   *
   * @param p
   */
  public void setPic(PictureItem p) {
    pic = p;
    ImageView image = (ImageView) findViewById(R.id.imageView1);
    image.setImageBitmap(pic.getPicture());
    image.setOnClickListener(
        new OnClickListener() {
          // Toggle whether the image gets the entire screen or not.
          @Override
          public void onClick(View v) {
            RelativeLayout relLay1 = (RelativeLayout) findViewById(R.id.RelativeLayout1);
            RelativeLayout relLay2 = (RelativeLayout) findViewById(R.id.RelativeLayout2);
            if (!imageOpen) { // The image is not already taking up the entire screen
              if (getResources().getConfiguration().orientation
                  == Configuration.ORIENTATION_LANDSCAPE) { // In Landscape
                relLay1.setLayoutParams(
                    new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 2f));
                relLay2.setLayoutParams(
                    new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 0f));

              } else { // In Portrait
                relLay1.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 2f));
                relLay2.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0f));
              }
              imageOpen = true;
            } else { // The image is already taking up the entire screen
              if (getResources().getConfiguration().orientation
                  == Configuration.ORIENTATION_LANDSCAPE) { // In Landscape
                relLay1.setLayoutParams(
                    new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
                relLay2.setLayoutParams(
                    new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));

              } else { // In Portrait
                relLay1.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
                relLay2.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
              }

              imageOpen = false;
            }
          }
        });
    TextView title = (TextView) findViewById(R.id.textView1);
    title.setText(pic.getTitle());
    TextView user = (TextView) findViewById(R.id.textView3);
    user.setText("By " + pic.getUser());
    ListView coms = (ListView) findViewById(R.id.listView1);
    TextView des = new TextView(this);
    des.setText(pic.getDescription());
    des.setTextSize(21);
    des.setTextColor(0xFFFFFFFF);
    coms.addHeaderView(des);
    coms.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            if (position != 0) {
              // QuestionAdapter quests = (QuestionAdapter) parent.getAdapter();
              theQuests.setOpenQuestion(position - 1);
              Button pushBut = (Button) findViewById(R.id.button1);
              if (theQuests.getOpenQuestion() == -1) {
                pushBut.setText("Post");
              } else {
                pushBut.setText("Reply");
              }
            }
          }
        });
    theQuests = new QuestionAdapter(this);
    theQuests.setQuestions(pic.getQuestions());
    coms.setAdapter(theQuests);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  }