(droid分享)新浪微博开发系列【十一】之查看微博正文

此页面用于展示并跳转查看特定微博的详细信息,包括作者、内容、图片、转发及评论等。

此篇为查看微博正文,点击listview跳转到此界面,好了,贴代码,在此说明一下,可能代码里调用一些方法在本篇中没有,但是全部在我的代码里,也不要索取图片,要看全部代码的请移步http://blog.csdn.net/gaojin1991/article/details/8022213

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/weibolinerlayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_activitycontent"
    android:orientation="vertical" >


    <RelativeLayout
        android:id="@+id/wbdetailTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#BB768e95" >


        <!-- android:background="@drawable/bg_title" -->


        <ImageButton
            android:id="@+id/wbdetailbtnClose"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@drawable/title_back"
            android:contentDescription="@string/contnetdescription" />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="@string/weibodetailsActivity_title"
            android:textColor="#000"
            android:textSize="20sp"
            android:textStyle="bold" />
    </RelativeLayout>


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >


        <ImageView
            android:id="@+id/wbdetailicon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:contentDescription="@string/contnetdescription" >
        </ImageView>


        <LinearLayout
            android:id="@+id/wbdetailcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:orientation="vertical"
            android:paddingLeft="0dp"
            android:paddingRight="5dp" >


            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >


                <TextView
                    android:id="@+id/wbdetailuser"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:textColor="#000000"
                    android:textSize="15dp"
                    android:textStyle="bold" >
                </TextView>


                <ImageView
                    android:id="@+id/wbdetailimageflag"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginRight="40dp"
                    android:contentDescription="@string/contnetdescription" />
            </RelativeLayout>


            <TextView
                android:id="@+id/wbdetailtext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:textColor="#000000"
                android:textSize="13dp"
                android:textStyle="bold" >
            </TextView>


            <ImageView
                android:id="@+id/wbdetailimage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:contentDescription="@string/contnetdescription" >
            </ImageView>
            <!-- 这是显示转发微博的部分 -->


            <TextView
                android:id="@+id/wbdetailcommitwbsourcetext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="4dp"
                android:textColor="#575757"
                android:textSize="13dp" >
            </TextView>


            <ImageView
                android:id="@+id/wbdetailcommitwbsourceimage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:contentDescription="@string/contnetdescription" >
            </ImageView>


            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >


                <!-- 微博来源 -->


                <TextView
                    android:id="@+id/wbdetailsource"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="4dp"
                    android:focusable="false"
                    android:textColor="#424952"
                    android:textSize="10dp" >
                </TextView>


                <RelativeLayout
                    android:id="@+id/wbdetailcountlayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginTop="3dp" >


                    <LinearLayout
                        android:id="@+id/wbdetailrepostlayout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal" >


                        <ImageView
                            android:id="@+id/wbdetailrepostsimg"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:contentDescription="@string/contnetdescription" >
                        </ImageView>


                        <TextView
                            android:id="@+id/wbdetailrepostscount"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="#424952"
                            android:textSize="10dp" >
                        </TextView>
                    </LinearLayout>


                    <LinearLayout
                        android:id="@+id/wbdetailcommentlayout"
                        android:layout_toRightOf="@+id/wbdetailrepostlayout"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal" >


                        <ImageView
                            android:id="@+id/wbdetailcommentsimg"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:contentDescription="@string/contnetdescription" >
                        </ImageView>


                        <TextView
                            android:id="@+id/wbdetailcommitcount"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="#424952"
                            android:textSize="10dp" >
                        </TextView>
                    </LinearLayout>
                </RelativeLayout>
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>


</LinearLayout>


package com.czu.sinaweibo;



import com.czu.downloadiconimage.AsyncImageLoader;
import com.czu.sinaweibo.R;
import com.czu.weiboadapter.WeiBoInfo;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView.BufferType;


/***
 * 查看微博详细信息
 * 
 * @author cit3d-02
 * 
 */
public class WeiBoDetailsActivity extends Activity {


/* 返回按钮 */
private ImageButton returnButton = null;


/* 对话框 */
// private ProgressDialog progressDialog;


private WeiBoHolder weiBoHolder = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);


setContentView(R.layout.weibodetails_activity);


final WeiBoInfo weiBoInfo = new WeiBoInfo();


weiBoInfo.setArticleId(this.getIntent().getStringExtra("ArticleId"));
weiBoInfo.setBigImage(this.getIntent().getStringExtra("BigImage"));
weiBoInfo.setCommentsCount(this.getIntent().getStringExtra(
"CommentsCount"));
weiBoInfo.setContent(this.getIntent().getStringExtra("Content"));
weiBoInfo.setImage(this.getIntent().getStringExtra("Image"));
weiBoInfo.setPublisherIcon(this.getIntent().getStringExtra(
"PublisherIcon"));
weiBoInfo
.setPublisherId(this.getIntent().getStringExtra("PublisherId"));
weiBoInfo.setPublisherName(this.getIntent().getStringExtra(
"PublisherName"));
weiBoInfo.setRepostsCount(this.getIntent().getStringExtra(
"RepostsCount"));
weiBoInfo.setSource(this.getIntent().getStringExtra("Source"));
weiBoInfo.setSourceBigImage(this.getIntent().getStringExtra(
"SourceBigImage"));
weiBoInfo.setSourceContent(this.getIntent().getStringExtra(
"SourceContent"));
weiBoInfo
.setSourceImage(this.getIntent().getStringExtra("SourceImage"));
weiBoInfo.setSourceName(this.getIntent().getStringExtra("SourceName"));
weiBoInfo.setHaveImage(Boolean.parseBoolean(this.getIntent()
.getStringExtra("HaveImage")));
weiBoInfo.setHaveSourceImage(Boolean.parseBoolean(this.getIntent()
.getStringExtra("HaveSourceImage")));
weiBoInfo.setHaveSourceStatus(Boolean.parseBoolean(this.getIntent()
.getStringExtra("HaveSourceStatus")));


weiBoHolder = new WeiBoHolder();


weiBoHolder.icon = (ImageView) this.findViewById(R.id.wbdetailicon);
weiBoHolder.text = (TextView) this.findViewById(R.id.wbdetailtext);
weiBoHolder.user = (TextView) this.findViewById(R.id.wbdetailuser);
weiBoHolder.imageflag = (ImageView) this
.findViewById(R.id.wbdetailimageflag);
weiBoHolder.image = (ImageView) this.findViewById(R.id.wbdetailimage);
weiBoHolder.source = (TextView) this.findViewById(R.id.wbdetailsource);
weiBoHolder.sourceText = (TextView) this
.findViewById(R.id.wbdetailcommitwbsourcetext);
weiBoHolder.sourceImage = (ImageView) this
.findViewById(R.id.wbdetailcommitwbsourceimage);


weiBoHolder.repostsImage = (ImageView) this
.findViewById(R.id.wbdetailrepostsimg);
weiBoHolder.repostsText = (TextView) this
.findViewById(R.id.wbdetailrepostscount);


weiBoHolder.commentsImage = (ImageView) this
.findViewById(R.id.wbdetailcommentsimg);
weiBoHolder.commentsText = (TextView) this
.findViewById(R.id.wbdetailcommitcount);


/* 设置文章内容 */
weiBoHolder.text.setText(weiBoInfo.getContent(), BufferType.SPANNABLE);


/* 设置微博作者的昵称 */
weiBoHolder.user.setText(weiBoInfo.getPublisherName());


// progressDialog = new ProgressDialog(WeiBoDetailsActivity.this);
// progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// progressDialog.setMessage("正在努力为您加载,请稍侯......");
//
// progressDialog.show();


/* 当该条微博包含图片时,设置一个标志,并且设置一个缩微图 */
if (weiBoInfo.getHaveImage()) {
weiBoHolder.imageflag.setImageResource(R.drawable.pic);
AsyncImageLoader asyncImageLoader = new AsyncImageLoader(
weiBoInfo.getImage(), weiBoHolder.image, true);
asyncImageLoader.setImage();
}


/* 异步下载微博作者头像 */
AsyncImageLoader asyncImageLoader = new AsyncImageLoader(
weiBoInfo.getPublisherIcon(), weiBoHolder.icon, true);
asyncImageLoader.setImage();


/* 如果微博中有retweeted_status那么就设置 */
if (weiBoInfo.getHaveSourceStatus()) {


weiBoHolder.sourceText.setText("@" + weiBoInfo.getSourceName()
+ ":" + weiBoInfo.getSourceContent());


if (weiBoInfo.getHaveSourceImage()) {
weiBoHolder.imageflag.setImageResource(R.drawable.pic);
AsyncImageLoader asyncRetweetedImageLoader = new AsyncImageLoader(
weiBoInfo.getSourceImage(), weiBoHolder.sourceImage,
true);
asyncRetweetedImageLoader.setImage();
}
}


/* 设置来源 */


String sourceString = weiBoInfo.getSource();
CharSequence charSequence = Html.fromHtml(sourceString);
weiBoHolder.source.setText("来自:" + charSequence);


/* 设置转发数目 */
String reposts_count = weiBoInfo.getRepostsCount();
weiBoHolder.repostsImage.setImageResource(R.drawable.icon_repost);
if (Integer.parseInt(reposts_count) > 0) {
weiBoHolder.repostsText.setText(reposts_count);
}


/* 设置评论数目 */
String comments_count = weiBoInfo.getCommentsCount();
weiBoHolder.commentsImage.setImageResource(R.drawable.icon_comment);
if (Integer.parseInt(comments_count) > 0) {
weiBoHolder.commentsText.setText(comments_count);
}


returnButton = (ImageButton) this.findViewById(R.id.wbdetailbtnClose);


returnButton.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
finish();
}
});


weiBoHolder.image.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
if (weiBoInfo.getHaveImage()) {
Intent intent = new Intent(WeiBoDetailsActivity.this,
ImageViewActivity.class);
intent.putExtra("ImageUrl", weiBoInfo.getBigImage());
startActivity(intent);
}


}
});


weiBoHolder.sourceImage.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
if (weiBoInfo.getHaveSourceImage()) {
Intent intent = new Intent(WeiBoDetailsActivity.this,
ImageViewActivity.class);
intent.putExtra("ImageUrl", weiBoInfo.getSourceBigImage());
startActivity(intent);
}
}
});


/* 对转发进行监听 */
LinearLayout repostLayout = (LinearLayout) this
.findViewById(R.id.wbdetailrepostlayout);
repostLayout.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
Intent intent = new Intent(WeiBoDetailsActivity.this,
RepostAndCommentActivity.class);
intent.putExtra("repostID", weiBoInfo.getArticleId());
intent.setFlags(0);
startActivity(intent);


}
});


/* 对评论进行监听 */
LinearLayout commentLayout = (LinearLayout) this
.findViewById(R.id.wbdetailcommentlayout);
commentLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {


Intent intent = new Intent(WeiBoDetailsActivity.this,
RepostAndCommentActivity.class);
intent.setFlags(1);
intent.putExtra("commentID", weiBoInfo.getArticleId());
startActivity(intent);


}
});


}


static class WeiBoHolder {
/* 存放微博发布者头像 */
ImageView icon;
/* 存放微博内容 */
TextView text;
/* 存放微博创建的时间 */
TextView time;
/* 创建微博发布者的姓名 */
TextView user;
/* 存放是否有微博图片 */
ImageView imageflag;
/* 存放微博图片缩微图 */
ImageView image;
/* 设置来源(设置通过何种客户端发布) */
TextView source;
/* 存放source的内容 */
TextView sourceText;
/* 存放source的图片 */
ImageView sourceImage;


/* 存放reposts图像 */
ImageView repostsImage;
/* 存放reposts数目 */
TextView repostsText;


/* 存放comments图像 */
ImageView commentsImage;
/* 存放comments数目 */
TextView commentsText;
}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值